NEAR CLI
The NEAR Command Line Interface (CLI) is a tool that enables to interact with the NEAR network directly from the shell. Among other things, the NEAR CLI enables you to:
- Create a new NEAR account
- Query information about an account
- Send Tokens such as NEAR, FTs, and NFTs
- Create, Add and Delete Account Keys
- Deploy a contract
- Call functions on a deployed contract
Installation​
- npm
- Cargo
- Mac and Linux (binaries)
- Windows (binaries)
npm install -g near-cli-rs@latest
$ cargo install near-cli-rs
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
irm https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.ps1 | iex
Configuration file​
The directory with access keys and available connection networks are defined in the configuration file (near-cli/config.toml
), which is located depending on the operating system in the following places:
- macOS:
$HOME/Library/Application Support
(e.g./Users/Alice/Library/Application Support
) - Linux:
$XDG_CONFIG_HOME
or$HOME/.config
(e.g./home/alice/.config
) - Windows:
{FOLDERID*RoamingAppData}
(e.g.C:\Users\Alice\AppData\Roaming
)
You can learn more about working with the configuration file here.
You can setup a custom RPC server by changing the rpc_url
parameter in near-cli
settings:
near config edit-connection testnet --key rpc_url --value https://archival-rpc.testnet.near.org/
Interactive mode​
To use the near-cli
simply run the following in your terminal.
$ near
You should then see the following. Use the arrow keys and hit enter
or simply type out one of the available options to select an option
We provide examples only of the most used commands. Such commands may have two versions - a full one and a short one. If you want to explore all options provided by near-cli
use the interactive mode described above.
Account​
This option will allow you to manage, control, and retrieve information on your accounts.
Summary​
view-account-summary
- view properties for an account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
near account view-account-summary $ACCOUNT_ID network-config testnet now
export ACCOUNT_ID=bob.testnet
near state $ACCOUNT_ID --networkId testnet
Import​
import-account
- import existing account (a.k.a. "sign in").
- Full
- Short
near account import-account using-web-wallet network-config testnet
near login --networkId testnet
Export​
export-account
- export existing account.
- Full
export ACCOUNT_ID=bob.testnet
near account export-account $ACCOUNT_ID using-web-wallet network-config testnet
Create​
create-account
- create a new account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
near account create-account sponsor-by-faucet-service $ACCOUNT_ID autogenerate-new-keypair save-to-keychain network-config testnet create
export ACCOUNT_ID=bob.testnet
near create-account $ACCOUNT_ID --useFaucet --networkId testnet
Delete​
delete-account
- delete an account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
export BENEFICIARY_ID=alice.testnet
near account delete-account $ACCOUNT_ID beneficiary $BENEFICIARY_ID network-config testnet sign-with-keychain send
export ACCOUNT_ID=bob.testnet
export BENEFICIARY_ID=alice.testnet
near delete-account $ACCOUNT_ID $BENEFICIARY_ID --networkId testnet
Keys​
Showing, adding and removing account keys.
List keys​
list-keys
- view a list of keys for an account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
near account list-keys $ACCOUNT_ID network-config testnet now
export ACCOUNT_ID=bob.testnet
near list-keys $ACCOUNT_ID --networkId testnet
Add key​
add-key
- add an access key to an account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
near account add-key $ACCOUNT_ID grant-full-access use-manually-provided-public-key ed25519:CXqAs8c8kZz81josLw82RQsnZXk8CAdUo7jAuN7uSht2 network-config testnet sign-with-keychain send
export ACCOUNT_ID=bob.testnet
near add-key $ACCOUNT_ID ed25519:CXqAs8c8kZz81josLw82RQsnZXk8CAdUo7jAuN7uSht2 --networkId testnet
Delete key​
delete-keys
- delete an access key from an account.
- Full
- Short
export ACCOUNT_ID=bob.testnet
near account delete-keys $ACCOUNT_ID public-keys ed25519:HdkFZFEPoWfgrrLK3R4t5dWtNoLC8WymBzhCXoP3zrjh network-config testnet sign-with-keychain send
export ACCOUNT_ID=bob.testnet
near delete-key $ACCOUNT_ID ed25519:HdkFZFEPoWfgrrLK3R4t5dWtNoLC8WymBzhCXoP3zrjh --networkId testnet
Tokens​
This will allow you to manage your token assets such as NEAR, FTs and NFTs.
Send NEAR​
send-near
- transfers NEAR to a specified recipient in units of NEAR or yoctoNEAR.
- Full
- Short
export ACCOUNT_ID=bob.testnet
export RECEIVER_ID=alice.testnet
near tokens $ACCOUNT_ID send-near $RECEIVER_ID '0.5 NEAR' network-config testnet sign-with-keychain send
export ACCOUNT_ID=bob.testnet
export RECEIVER_ID=alice.testnet
near send-near $ACCOUNT_ID $RECEIVER_ID 0.5 --networkId testnet
Send FT​
send-ft
- transfer Fungible Tokens to a specified user.
- Full
export ACCOUNT_ID=bob.testnet
export RECEIVER_ID=alice.testnet
export FT_CONTRACT_ID=0c97251cd1f630c444dbusdt.testnet
near tokens $ACCOUNT_ID send-ft $FT_CONTRACT_ID $RECEIVER_ID amount-ft '1 USDT' prepaid-gas '100.0 Tgas' attached-deposit '1 yoctoNEAR' network-config testnet sign-with-keychain send
Send NFT​
send-nft
- transfers NFTs between accounts.
- Full
export ACCOUNT_ID=bob.testnet
export RECEIVER_ID=alice.testnet
export NFT_CONTRACT_ID=nft.examples.testnet
near tokens $ACCOUNT_ID send-nft $NFT_CONTRACT_ID $RECEIVER_ID 1 --prepaid-gas '100.0 Tgas' --attached-deposit '1 yoctoNEAR' network-config testnet sign-with-keychain send
View NEAR balance​
view-near-balance
- view the balance of NEAR tokens.
- Full
export ACCOUNT_ID=bob.testnet
near tokens $ACCOUNT_ID view-near-balance network-config testnet now