General purpose command line tools for interacting with NEAR Protocol
General purpose command line tools for interacting with NEAR Protocol
This project will no longer receive any updates.
We strongly recommend everyone to migrate to near-cli-rs instead.
NEAR CLI is a Node.js application that relies on near-api-js to connect to and interact with the NEAR blockchain. Create accounts, access keys, sign & send transactions with this versatile command line interface tool.
Note: Node.js version 16+ is required to run NEAR CLI.
This release is a major reorganization of the codebase to simplify its maintenance. It also includes a few new features and a multitude of small fixes.
The most notable changes are:
--useLedger does not set the path anymore, use --ledgerPath for thisadd-credentials commandgenerate-key command now has a --saveImplicit option to save the key as an implicit accounttestnet pre-funded accounts using the --useFaucet option TLA with less than 32 characters anymore (this is a NEAR protocol change)view now does not take an --accountId or --masterAccountnear create-account to see how options might have changedRelease notes and unreleased changes can be found in the CHANGELOG
Click on a command for more information and examples.
| Command | Description |
|---|---|
| ACCESS KEYS | |
near add-credentials |
Stores credentials for an account locally |
near add-key |
adds a new access key to an account |
near delete-key |
deletes an access key from an account |
near generate-key |
generates a key pair and optionally stores it locally as credentials for an accountId |
near list-keys |
displays all access keys and their details for a given account |
near login |
stores a full access key locally using NEAR Wallet |
| ACCOUNTS | |
near create-account |
creates a new account, either using a faucet to fund it, or an account saved locally |
near delete-account |
deletes an account and transfers remaining balance to a beneficiary account |
near list-keys |
displays all access keys for a given account |
near send-near |
sends tokens from one account to another |
near state |
shows general details of an account |
| CONTRACTS | |
near call |
makes a contract call which can invoke change or view methods |
near deploy |
deploys a smart contract to the NEAR blockchain |
near storage |
Shows the storage state of a given contract, i.e. the data stored in a contract |
near view |
makes a contract call which can only invoke a view method |
| TRANSACTIONS | |
near tx-status |
queries a transaction's status by txHash |
Make sure you have a current version of
npmandNodeJSinstalled.
npm and node using a package manager like nvm as sometimes there are issues using Ledger due to how OS X handles node packages related to USB devices. [click here]near-cli globally by running:npm install -g near-cliFor example, on Ubuntu 20.04 near-cli can be installed by running:
# Install nvm (https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
# Install node
nvm install node
# Install near-cli
npm install -g near-cli
# near-cli works!
near --helpFor Windows users, we recommend using Windows Subsystem for Linux (
WSL).
WSL [click here]npm [click here] Node.js [ click here ]npm default directory [ click here ] WSLWSL and install near-cli globally by running:npm install -g near-cliThe default network for
near-cliistestnet.
NEAR_NETWORK=testnet near send ...export NEAR_NETWORK=mainnet--networkId option.near send-near ... --networkId mainnet[!WARNING] In previous versions,
near-cliusedNEAR_ENVto set the network. This can still be used, butNEAR_NETWORKhas priority overNEAR_ENVif both are set.
You can set custom RPC server URL by setting this env variables:
NEAR_MAINNET_RPC
NEAR_TESTNET_RPCClear them in case you want to get back to the default RPC server.
Example:
export NEAR_TESTNET_RPC=https://rpc.testnet.near.orgAll keys are stored locally at the root of your HOME directory:
~/.near-credentials (MAC / Linux)C:\Users\YOUR_ACCOUNT\.near-credentials (Windows)Inside .near-credentials, access keys are organized in network subdirectories: testnet, and mainnet.
These network subdirectories contain .JSON objects with an:
account_idprivate_keypublic_keynear add-credentials Stores credentials (full-access-key) locally for an already existing account.
accountId--seedPhrase or --secretKeyExamples:
near add-credentials example-acct.testnet --seedPhrase "antique attitude say evolve ring arrive hollow auto wide bronze usual unfold"near add-keyAdds either a full access or function access key to a given account.
Optionally allows to sign with a Ledger:
--signWithLedger--ledgerPath
Note: You will use an existing full access key for the account you would like to add a new key to. (near login)
full access keyaccountId publicKeyExample:
near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1SExample Response
Adding full access key = Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S to example-acct.testnet.
Transaction Id EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJgfunction call keyaccountId publicKey --contract-id--method-names --allowance
accountIdis the account you are adding the key to
--contract-idis the contract you are allowing methods to be called on
--method-namesare optional and if omitted, all methods of the--contract-idcan be called.
--allowanceis the amount of Ⓝ the key is allowed to spend on gas fees only (default: 0).
Note: Each transaction made with this key will have gas fees deducted from the initial allowance and once it runs out a new key must be issued.
Example:
near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000Example Response
Adding function call access key = GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi to example-acct.testnet.
Transaction Id H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2rnear delete-keyDeletes an existing key for a given account. Optionally allows to sign with a Ledger:
--signWithLedger--ledgerPath
accountId publicKey--networkId, forceNote: You will need separate full access key for the account you would like to delete a key from. (near login)
Example:
near delete-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1SExample Response
Transaction Id 4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFTnear generate-keyDisplays a key-pair and seed-phrase and optionally stores it locally in
.near-credentials.
accountId or none--fromSeedPhrase, --saveImplicit, --queryLedgerPKNote: There are several ways to use generate-key that return very different results. Please reference the examples below for further details.
near generate-keyCreates and displays a key pair
near generate-keyExample Response
Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411near generate-key --saveImplicitCreates and displays a key pair, saving it lo
No open issues yet, or sync has not completed.