Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

near-cli

> 开发工具
Open source

General purpose command line tools for interacting with NEAR Protocol

200 stars0 likes1 views
WebsiteGitHub

About

General purpose command line tools for interacting with NEAR Protocol

[DEPRECATED] NEAR CLI (command line interface)

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.

v4.0.0 Notes

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:

  • Ledger users, please notice that the --useLedger does not set the path anymore, use --ledgerPath for this
    • Please check the commands that support Ledger for more details
  • Users can now import credentials using the add-credentials command
  • The generate-key command now has a --saveImplicit option to save the key as an implicit account
  • Users can create testnet pre-funded accounts using the --useFaucet option
  • Accounts cannot create TLA with less than 32 characters anymore (this is a NEAR protocol change)
  • Removed unnecessary options from commands, e.g. view now does not take an --accountId or --masterAccount
  • If a command does not work, please first check the commands help to see if the options have changed
    • For example, run near create-account to see how options might have changed

Release notes

Release notes and unreleased changes can be found in the CHANGELOG

Overview

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

Setup

Installation

Make sure you have a current version of npm and NodeJS installed.

Mac and Linux

  1. Install 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]
  2. Ensure you have installed Node version 12 or above.
  3. Install near-cli globally by running:
bash
npm install -g near-cli

For example, on Ubuntu 20.04 near-cli can be installed by running:

bash
# 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 --help

Windows

For Windows users, we recommend using Windows Subsystem for Linux (WSL).

  1. Install WSL [click here]
  2. Install npm [click here]
  3. Install Node.js [ click here ]
  4. Change npm default directory [ click here ]
    • This is to avoid any permission issues with WSL
  5. Open WSL and install near-cli globally by running:
bash
npm install -g near-cli

Network selection

The default network for near-cli is testnet.

  • You can change the network by prepending an environment variable to your command.
bash
NEAR_NETWORK=testnet near send ...
  • Alternatively, you can set up a global environment variable by running:
bash
export NEAR_NETWORK=mainnet
  • All commands that interact with the network also allow to pass the --networkId option.
bash
near send-near ... --networkId mainnet

[!WARNING] In previous versions, near-cli used NEAR_ENV to set the network. This can still be used, but NEAR_NETWORK has priority over NEAR_ENV if both are set.


Custom RPC server selection

You can set custom RPC server URL by setting this env variables:

bash
NEAR_MAINNET_RPC
NEAR_TESTNET_RPC

Clear them in case you want to get back to the default RPC server.

Example:

bash
export NEAR_TESTNET_RPC=https://rpc.testnet.near.org

Access Keys

All 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_id
  • private_key
  • public_key

near add-credentials

Stores credentials (full-access-key) locally for an already existing account.

  • arguments: accountId
  • options: --seedPhrase or --secretKey

Examples:

bash
near add-credentials example-acct.testnet --seedPhrase "antique attitude say evolve ring arrive hollow auto wide bronze usual unfold"

near add-key

Adds 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)

1) add a full access key

  • arguments: accountId publicKey

Example:

bash
near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S

Example 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/EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg

2) add a function call key

  • arguments: accountId publicKey --contract-id
  • options: --method-names --allowance

accountId is the account you are adding the key to

--contract-id is the contract you are allowing methods to be called on

--method-names are optional and if omitted, all methods of the --contract-id can be called.

--allowance is 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:

bash
near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000

Example 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/H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r

near delete-key

Deletes an existing key for a given account. Optionally allows to sign with a Ledger: --signWithLedger --ledgerPath

  • arguments: accountId publicKey
  • options: --networkId, force

Note: You will need separate full access key for the account you would like to delete a key from. (near login)

Example:

bash
near delete-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S

Example Response

Transaction Id 4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT

near generate-key

Displays a key-pair and seed-phrase and optionally stores it locally in .near-credentials.

  • arguments: accountId or none
  • options: --fromSeedPhrase, --saveImplicit, --queryLedgerPK

Note: There are several ways to use generate-key that return very different results. Please reference the examples below for further details.


1a) near generate-key

Creates and displays a key pair

bash
near generate-key

Example Response

bash
Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411

1b) near generate-key --saveImplicit

Creates and displays a key pair, saving it lo

Issues· 58 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptblockchaindevtoolsnearprotocolsmart-contracts

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具