Skip to main content

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:

  • Login with a NEAR account
  • Deploy a contract
  • Interact and query information from a deployed contract

Installationโ€‹

npm install -g near-cli-rs@latest

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.

Custom RPC

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

important

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.

export ACCOUNT_ID=bob.testnet
near account view-account-summary $ACCOUNT_ID network-config testnet now

Importโ€‹

import-account - import existing account (a.k.a. "sign in").

near account import-account using-web-wallet network-config testnet

Exportโ€‹

export-account - export existing account.

export ACCOUNT_ID=bob.testnet
near account export-account $ACCOUNT_ID using-web-wallet network-config testnet

Createโ€‹

create-account - create a new account.

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

Deleteโ€‹

delete-account - delete an account.

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

Keysโ€‹

Showing, adding and removing account keys.

List keysโ€‹

list-keys - view a list of keys for an account.

export ACCOUNT_ID=bob.testnet
near account list-keys $ACCOUNT_ID network-config testnet now

Add keyโ€‹

add-key - add an access key to an account.

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

Delete keyโ€‹

delete-keys - delete an access key from an account.

export ACCOUNT_ID=bob.testnet
near account delete-keys $ACCOUNT_ID public-keys ed25519:HdkFZFEPoWfgrrLK3R4t5dWtNoLC8WymBzhCXoP3zrjh network-config testnet sign-with-keychain send

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.

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

Send FTโ€‹

send-ft - transfer Fungible Tokens to a specified user.

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.

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.

export ACCOUNT_ID=bob.testnet
near tokens $ACCOUNT_ID view-near-balance network-config testnet now

View FT balanceโ€‹

view-ft-balance - view the balance of Fungible Tokens.

export ACCOUNT_ID=bob.testnet
export FT_CONTRACT_ID=0c97251cd1f630c444dbusdt.testnet
near tokens $ACCOUNT_ID view-ft-balance $FT_CONTRACT_ID network-config testnet now

View NFT balanceโ€‹

view-nft-assets - view the balance of NFT tokens.

export ACCOUNT_ID=bob.testnet
export NFT_CONTRACT_ID=nft.examples.testnet
near tokens $ACCOUNT_ID view-nft-assets $NFT_CONTRACT_ID network-config testnet now

Contractโ€‹

This option allows you to manage and interact with your smart contracts.

Callโ€‹

call-function - execute function (contract method).

# View method
export CONTRACT_ID=nft.examples.testnet
near contract call-function as-read-only $CONTRACT_ID nft_tokens json-args '{"from_index": "0", "limit": 2}' network-config testnet now

# Call method
export ACCOUNT_ID=bob.testnet
near contract call-function as-transaction $CONTRACT_ID nft_mint json-args '{"metadata": {"copies": 1, "description": "The Team Goes", "media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/", "title": "GO TEAM"}, "receiver_id": "bob.testnet", "token_id": "5895"}' prepaid-gas '100.0 Tgas' attached-deposit '0.1 NEAR' sign-as $ACCOUNT_ID network-config testnet sign-with-keychain send

Deployโ€‹

deploy - add a new contract code.

export CONTRACT_ID=contract.testnet
near contract deploy $CONTRACT_ID use-file ../target/near/contract.wasm without-init-call network-config testnet sign-with-keychain send

Inspectโ€‹

inspect - get a list of available function names.

export CONTRACT_ID=nft.examples.testnet
near contract view-storage $CONTRACT_ID all as-text network-config testnet now

Transactionโ€‹

Operate transactions.

View statusโ€‹

view-status - view a transaction status.

near transaction view-status BFrVVtjqD2p1zYX1UCvn4nJpy7zPHpY5cTgQaKCZjBvw network-config testnet

Configโ€‹

Manage the connection parameters inside the config.toml file for near-cli.

This will allow you to change or modify the network connections for your CLI.

Show connectionsโ€‹

show-connections - show a list of network connections.

near config show-connections

Edit connectionโ€‹

edit-connection - edit a network connection.

near config edit-connection testnet --key rpc_url --value https://test.rpc.fastnear.com

important

We provide examples only of the most used commands. If you want to explore all options provided by near-cli use the interactive mode.

Was this page helpful?