near-cli-rs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SKILL: near-cli-rs — NEAR Protocol CLI Reference for AI Agents

技能:near-cli-rs — 面向AI Agent的NEAR Protocol CLI参考文档

Purpose: This file is for LLMs generating non-interactive
near
commands. When a user request maps to a CLI action, look up the correct syntax here, construct the complete one-liner, show it to the user for approval, then execute it.
Rule: Always produce complete commands from
near
through the final action token (
send
,
display
,
now
,
create
, etc.). Never omit
network-config <NETWORK>
.
Version: near-cli-rs v0.14+ (tested through v0.24)

用途:本文件用于大语言模型生成非交互式
near
命令。当用户请求对应某个CLI操作时,在此处查找正确的语法,构建完整的单行命令,展示给用户确认后再执行。
规则:始终生成从
near
开始到最终操作令牌(
send
display
now
create
等)的完整命令。绝不能省略
network-config <NETWORK>
版本:near-cli-rs v0.14+(已在v0.24版本测试通过)

Command Grammar

命令语法

near [GLOBAL_FLAGS] <COMMAND_GROUP> [ENTITY_ARGS] <SUBCOMMAND> [SUB_ARGS] network-config <NETWORK> [SIGNING_OPTION] [FINAL_ACTION]
  • View commands end with:
    now
    |
    at-block-height <N>
    |
    at-block-hash <HASH>
  • Transaction commands end with a signing option followed by
    send
    or
    display
  • Account creation via faucet ends with
    create
  • network-config
    keyword is always required (even for view commands)

near [全局标志] <命令组> [实体参数] <子命令> [子参数] network-config <网络> [签名选项] [最终操作]
  • 查询类命令以以下结尾:
    now
    |
    at-block-height <N>
    |
    at-block-hash <HASH>
  • 交易类命令以签名选项加
    send
    display
    结尾
  • 通过水龙头创建账户
    create
    结尾
  • network-config
    关键字必须始终添加(即使是查询类命令)

Global Flags

全局标志

FlagEffect
--offline
Create/sign tx without network access
--quiet
Suppress progress output (recommended for scripting)
--teach-me
Print all RPC calls and their parameters

标志作用
--offline
无需网络连接即可创建/签署交易
--quiet
抑制进度输出(脚本编写推荐使用)
--teach-me
打印所有RPC调用及其参数

Networks and View Qualifiers

网络与查询限定符

ItemValue
Built-in networks
mainnet
,
testnet
Custom networkany
<connection-name>
from
near config show-connections
View: latest block
now
View: specific height
at-block-height <BLOCK_HEIGHT>
View: specific hash
at-block-hash <BLOCK_HASH>

内置网络
mainnet
,
testnet
自定义网络来自
near config show-connections
的任意
<connection-name>
查询:最新区块
now
查询:指定区块高度
at-block-height <BLOCK_HEIGHT>
查询:指定区块哈希
at-block-hash <BLOCK_HASH>

Amount and Gas Formats

金额与Gas格式

AssetFormatNotes
NEAR
'1 NEAR'
or
'0.5 NEAR'
Quoted, space before unit
yoctoNEAR
'1 yoctoNEAR'
Required deposit for many contract calls
Gas
'30 Tgas'
to
'300 Tgas'
Default
'100 Tgas'
, max
'300 Tgas'
FT amount
'10 usn'
Number + FT symbol, quoted
FT all
all
Transfer entire balance

资产格式说明
NEAR
'1 NEAR'
'0.5 NEAR'
需加引号,单位前有空格
yoctoNEAR
'1 yoctoNEAR'
许多合约调用所需的最低押金
Gas
'30 Tgas'
'300 Tgas'
默认值
'100 Tgas'
,最大值
'300 Tgas'
FT金额
'10 usn'
数字+FT符号,需加引号
FT全部余额
all
转账全部余额

Signing Options Reference

签名选项参考

Replace
<SIGNING_OPTION>
in any transaction command with one of:
OptionFull syntax
OS keychain (recommended)
sign-with-keychain send
Legacy keychain (
~/.near-credentials/
)
sign-with-legacy-keychain send
Ledger hardware wallet
sign-with-ledger send
Plaintext private key
sign-with-plaintext-private-key --signer-public-key ed25519:<PUBKEY> --signer-private-key ed25519:<PRIVKEY> send
Access key file
sign-with-access-key-file /path/to/key.json send
Seed phrase
sign-with-seed-phrase 'word1 ... word12' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' send
MPC
sign-with-mpc send
Produce unsigned tx (sign later)
sign-later
Replace
send
with
display
to print the signed transaction in base64 without broadcasting.

将任意交易类命令中的
<SIGNING_OPTION>
替换为以下选项之一:
选项完整语法
操作系统钥匙串(推荐)
sign-with-keychain send
旧版钥匙串(
~/.near-credentials/
sign-with-legacy-keychain send
Ledger硬件钱包
sign-with-ledger send
明文私钥
sign-with-plaintext-private-key --signer-public-key ed25519:<PUBKEY> --signer-private-key ed25519:<PRIVKEY> send
访问密钥文件
sign-with-access-key-file /path/to/key.json send
助记词
sign-with-seed-phrase 'word1 ... word12' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' send
MPC
sign-with-mpc send
生成未签名交易(后续签名)
sign-later
send
替换为
display
可打印Base64格式的已签名交易,而不广播至网络。

account
Commands

account
命令

view-account-summary

查看账户摘要

sh
undefined
sh
undefined

Current block

当前区块

near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> now
near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> now

Specific block height

指定区块高度

near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> at-block-height <BLOCK_HEIGHT>
near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> at-block-height <BLOCK_HEIGHT>

Specific block hash

指定区块哈希

near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> at-block-hash <BLOCK_HASH>
undefined
near account view-account-summary <ACCOUNT_ID> network-config <NETWORK> at-block-hash <BLOCK_HASH>
undefined

import-account

导入账户

sh
undefined
sh
undefined

Using seed phrase (non-interactive)

使用助记词(非交互式)

near account import-account using-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' network-config <NETWORK>
near account import-account using-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' network-config <NETWORK>

Using private key

使用私钥

near account import-account using-private-key ed25519:<PRIVATE_KEY> network-config <NETWORK>
near account import-account using-private-key ed25519:<PRIVATE_KEY> network-config <NETWORK>

NOTE: using-web-wallet requires a browser redirect — not suitable for non-interactive use

注意:using-web-wallet需要浏览器重定向——不适合非交互式使用

undefined
undefined

export-account

导出账户

sh
undefined
sh
undefined

Export as seed phrase

导出为助记词

near account export-account <ACCOUNT_ID> using-seed-phrase network-config <NETWORK>
near account export-account <ACCOUNT_ID> using-seed-phrase network-config <NETWORK>

Export as private key

导出为私钥

near account export-account <ACCOUNT_ID> using-private-key network-config <NETWORK>
undefined
near account export-account <ACCOUNT_ID> using-private-key network-config <NETWORK>
undefined

create-account

创建账户

sh
undefined
sh
undefined

Testnet faucet (testnet only) — autogenerate keypair

测试网水龙头(仅测试网)——自动生成密钥对

near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> autogenerate-new-keypair save-to-keychain network-config testnet create
near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> autogenerate-new-keypair save-to-keychain network-config testnet create

Testnet faucet — use known seed phrase

测试网水龙头——使用已知助记词

near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> use-manually-provided-seed-phrase '<SEED_PHRASE>' network-config testnet create
near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> use-manually-provided-seed-phrase '<SEED_PHRASE>' network-config testnet create

Testnet faucet — use known public key

测试网水龙头——使用已知公钥

near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> use-manually-provided-public-key ed25519:<PUBKEY> network-config testnet create
near account create-account sponsor-by-faucet-service <NEW_ACCOUNT_ID> use-manually-provided-public-key ed25519:<PUBKEY> network-config testnet create

Fund-myself: create sub-account (signer is implicit from keychain)

自行出资:创建子账户(签名者由钥匙串自动识别)

near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' autogenerate-new-keypair save-to-keychain sign-as network-config <NETWORK> sign-with-keychain send
near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' autogenerate-new-keypair save-to-keychain sign-as network-config <NETWORK> sign-with-keychain send

Fund-myself: create account specifying explicit signer

自行出资:创建账户并指定签名者

near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' autogenerate-new-keypair save-to-keychain sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' autogenerate-new-keypair save-to-keychain sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

Fund-myself: use known seed phrase for new account

自行出资:使用已知助记词创建新账户

near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' use-manually-provided-seed-phrase '<SEED_PHRASE>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' use-manually-provided-seed-phrase '<SEED_PHRASE>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

Fund-myself: use known public key for new account

自行出资:使用已知公钥创建新账户

near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' use-manually-provided-public-key ed25519:<PUBKEY> sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined
near account create-account fund-myself <NEW_ACCOUNT_ID> '<INITIAL_BALANCE>' use-manually-provided-public-key ed25519:<PUBKEY> sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined

delete-account

删除账户

sh
near account delete-account <ACCOUNT_ID> beneficiary <BENEFICIARY_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
sh
near account delete-account <ACCOUNT_ID> beneficiary <BENEFICIARY_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

list-keys

列出密钥

sh
near account list-keys <ACCOUNT_ID> network-config <NETWORK> now
sh
near account list-keys <ACCOUNT_ID> network-config <NETWORK> now

get-public-key

获取公钥

sh
undefined
sh
undefined

From seed phrase

从助记词获取

near account get-public-key from-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path "m/44'/397'/0'"
near account get-public-key from-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path "m/44'/397'/0'"

From plaintext private key

从明文私钥获取

near account get-public-key from-plaintext-private-key ed25519:<PRIVATE_KEY>
near account get-public-key from-plaintext-private-key ed25519:<PRIVATE_KEY>

From OS keychain

从操作系统钥匙串获取

near account get-public-key from-keychain <ACCOUNT_ID> network-config <NETWORK>
near account get-public-key from-keychain <ACCOUNT_ID> network-config <NETWORK>

From legacy keychain

从旧版钥匙串获取

near account get-public-key from-legacy-keychain <ACCOUNT_ID> network-config <NETWORK>
near account get-public-key from-legacy-keychain <ACCOUNT_ID> network-config <NETWORK>

From Ledger (requires 5-component path)

从Ledger获取(需5段路径)

near account get-public-key from-ledger --seed-phrase-hd-path "m/44'/397'/0'/0'/1'"
undefined
near account get-public-key from-ledger --seed-phrase-hd-path "m/44'/397'/0'/0'/1'"
undefined

add-key

添加密钥

sh
undefined
sh
undefined

Add full-access key (provide existing public key)

添加全权限密钥(提供现有公钥)

near account add-key <ACCOUNT_ID> grant-full-access use-manually-provided-public-key ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send
near account add-key <ACCOUNT_ID> grant-full-access use-manually-provided-public-key ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send

Add function-call-only key (autogenerate keypair)

添加仅函数调用权限密钥(自动生成密钥对)

near account add-key <ACCOUNT_ID> grant-function-call-access --allowance '<ALLOWANCE>' --contract-account-id <CONTRACT_ID> --function-names '<METHOD1>, <METHOD2>' autogenerate-new-keypair save-to-keychain network-config <NETWORK> sign-with-keychain send
near account add-key <ACCOUNT_ID> grant-function-call-access --allowance '<ALLOWANCE>' --contract-account-id <CONTRACT_ID> --function-names '<METHOD1>, <METHOD2>' autogenerate-new-keypair save-to-keychain network-config <NETWORK> sign-with-keychain send

Add function-call-only key (allow all methods on contract)

添加仅函数调用权限密钥(允许合约所有方法)

near account add-key <ACCOUNT_ID> grant-function-call-access --allowance '<ALLOWANCE>' --contract-account-id <CONTRACT_ID> --function-names '' use-manually-provided-public-key ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send
undefined
near account add-key <ACCOUNT_ID> grant-function-call-access --allowance '<ALLOWANCE>' --contract-account-id <CONTRACT_ID> --function-names '' use-manually-provided-public-key ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send
undefined

delete-keys

删除密钥

sh
near account delete-keys <ACCOUNT_ID> public-keys ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send
sh
near account delete-keys <ACCOUNT_ID> public-keys ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain send

manage-storage-deposit

管理存储押金

sh
undefined
sh
undefined

View storage balance

查看存储余额

near account manage-storage-deposit <CONTRACT_ID> view-balance <ACCOUNT_ID> network-config <NETWORK> now
near account manage-storage-deposit <CONTRACT_ID> view-balance <ACCOUNT_ID> network-config <NETWORK> now

Deposit storage

存储押金充值

near account manage-storage-deposit <CONTRACT_ID> deposit <ACCOUNT_ID> '<AMOUNT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
near account manage-storage-deposit <CONTRACT_ID> deposit <ACCOUNT_ID> '<AMOUNT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

Withdraw from storage

提取存储押金

near account manage-storage-deposit <CONTRACT_ID> withdraw '<AMOUNT>' sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined
near account manage-storage-deposit <CONTRACT_ID> withdraw '<AMOUNT>' sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined

update-social-profile

更新社交资料

sh
undefined
sh
undefined

Update profile with JSON args

使用JSON参数更新资料

near account update-social-profile <ACCOUNT_ID> json-args '{"name":"<NAME>","image":{"ipfs_cid":"<CID>"}}' sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
near account update-social-profile <ACCOUNT_ID> json-args '{"name":"<NAME>","image":{"ipfs_cid":"<CID>"}}' sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

Update profile from file

从文件更新资料

near account update-social-profile <ACCOUNT_ID> file-args /path/to/profile.json sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

---
near account update-social-profile <ACCOUNT_ID> file-args /path/to/profile.json sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

---

tokens
Commands

tokens
命令

view-near-balance

查看NEAR余额

sh
near tokens <ACCOUNT_ID> view-near-balance network-config <NETWORK> now
sh
near tokens <ACCOUNT_ID> view-near-balance network-config <NETWORK> now

view-ft-balance

查看FT余额

sh
near tokens <ACCOUNT_ID> view-ft-balance <FT_CONTRACT_ID> network-config <NETWORK> now
sh
near tokens <ACCOUNT_ID> view-ft-balance <FT_CONTRACT_ID> network-config <NETWORK> now

view-nft-assets

查看NFT资产

sh
near tokens <ACCOUNT_ID> view-nft-assets <NFT_CONTRACT_ID> network-config <NETWORK> now
sh
near tokens <ACCOUNT_ID> view-nft-assets <NFT_CONTRACT_ID> network-config <NETWORK> now

send-near

转账NEAR

sh
near tokens <SENDER_ACCOUNT_ID> send-near <RECEIVER_ACCOUNT_ID> '<AMOUNT>' network-config <NETWORK> sign-with-keychain send
sh
near tokens <SENDER_ACCOUNT_ID> send-near <RECEIVER_ACCOUNT_ID> '<AMOUNT>' network-config <NETWORK> sign-with-keychain send

send-ft

转账FT

sh
undefined
sh
undefined

Send specific amount

转账指定金额

near tokens <SENDER_ACCOUNT_ID> send-ft <FT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> '<AMOUNT>' memo '<MEMO>' network-config <NETWORK> sign-with-keychain send
near tokens <SENDER_ACCOUNT_ID> send-ft <FT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> '<AMOUNT>' memo '<MEMO>' network-config <NETWORK> sign-with-keychain send

Send all tokens (with optional custom gas/deposit)

转账全部代币(可自定义Gas/押金)

near tokens <SENDER_ACCOUNT_ID> send-ft <FT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> all memo '' --prepaid-gas '300.0 Tgas' --attached-deposit '1 yoctoNEAR' network-config <NETWORK> sign-with-keychain send

Note: Default `prepaid-gas` is `'100.0 Tgas'` and `attached-deposit` is `'1 yoctoNEAR'`.
near tokens <SENDER_ACCOUNT_ID> send-ft <FT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> all memo '' --prepaid-gas '300.0 Tgas' --attached-deposit '1 yoctoNEAR' network-config <NETWORK> sign-with-keychain send

注意:默认`prepaid-gas`为`'100.0 Tgas'`,`attached-deposit`为`'1 yoctoNEAR'`。

send-nft

转账NFT

sh
near tokens <SENDER_ACCOUNT_ID> send-nft <NFT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> <TOKEN_ID> --prepaid-gas '300.0 Tgas' --attached-deposit '1 yoctoNEAR' network-config <NETWORK> sign-with-keychain send

sh
near tokens <SENDER_ACCOUNT_ID> send-nft <NFT_CONTRACT_ID> <RECEIVER_ACCOUNT_ID> <TOKEN_ID> --prepaid-gas '300.0 Tgas' --attached-deposit '1 yoctoNEAR' network-config <NETWORK> sign-with-keychain send

staking
Commands

staking
命令

validator-list

验证者列表

sh
near staking validator-list network-config <NETWORK>
sh
near staking validator-list network-config <NETWORK>

delegation

质押委托

sh
undefined
sh
undefined

View delegated stake balance

查看委托质押余额

near staking delegation <ACCOUNT_ID> view-balance <POOL_ID> network-config <NETWORK> now
near staking delegation <ACCOUNT_ID> view-balance <POOL_ID> network-config <NETWORK> now

Deposit and stake (send NEAR to pool and immediately stake)

充值并质押(向质押池转入NEAR并立即质押)

near staking delegation <ACCOUNT_ID> deposit-and-stake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> deposit-and-stake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send

Stake previously deposited tokens

质押已充值的代币

near staking delegation <ACCOUNT_ID> stake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> stake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send

Stake all previously deposited or unstaked tokens

质押所有已充值或已解锁的代币

near staking delegation <ACCOUNT_ID> stake-all <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> stake-all <POOL_ID> network-config <NETWORK> sign-with-keychain send

Unstake a specific amount

解锁指定金额

near staking delegation <ACCOUNT_ID> unstake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> unstake '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send

Unstake everything

解锁全部金额

near staking delegation <ACCOUNT_ID> unstake-all <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> unstake-all <POOL_ID> network-config <NETWORK> sign-with-keychain send

Withdraw a specific amount (after unstaking + ~2 epoch wait)

提取指定金额(解锁后需等待约2个纪元)

near staking delegation <ACCOUNT_ID> withdraw '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send
near staking delegation <ACCOUNT_ID> withdraw '<AMOUNT>' <POOL_ID> network-config <NETWORK> sign-with-keychain send

Withdraw all available unstaked tokens

提取所有可解锁代币

near staking delegation <ACCOUNT_ID> withdraw-all <POOL_ID> network-config <NETWORK> sign-with-keychain send

**Note:** Unstaked funds require approximately 2 epochs (~48 hours) before they can be withdrawn.

---
near staking delegation <ACCOUNT_ID> withdraw-all <POOL_ID> network-config <NETWORK> sign-with-keychain send

**注意**:解锁后的资金需等待约2个纪元(约48小时)后方可提取。

---

contract
Commands

contract
命令

call-function (view/read-only)

调用函数(查询/只读)

sh
undefined
sh
undefined

With JSON args

使用JSON参数

near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> json-args '{"key":"value"}' network-config <NETWORK> now
near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> json-args '{"key":"value"}' network-config <NETWORK> now

With empty args

使用空参数

near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> empty-args network-config <NETWORK> now
near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> empty-args network-config <NETWORK> now

With text args

使用文本参数

near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> text-args '<STRING>' network-config <NETWORK> now
near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> text-args '<STRING>' network-config <NETWORK> now

With base64 args

使用Base64参数

near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> base64-args '<BASE64>' network-config <NETWORK> now
undefined
near contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> base64-args '<BASE64>' network-config <NETWORK> now
undefined

call-function (transaction/state-changing)

调用函数(交易/改变状态)

sh
undefined
sh
undefined

With JSON args

使用JSON参数

near contract call-function as-transaction <CONTRACT_ID> <METHOD_NAME> json-args '{"key":"value"}' prepaid-gas '<GAS>' attached-deposit '<DEPOSIT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
near contract call-function as-transaction <CONTRACT_ID> <METHOD_NAME> json-args '{"key":"value"}' prepaid-gas '<GAS>' attached-deposit '<DEPOSIT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send

With empty args

使用空参数

near contract call-function as-transaction <CONTRACT_ID> <METHOD_NAME> empty-args prepaid-gas '<GAS>' attached-deposit '<DEPOSIT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined
near contract call-function as-transaction <CONTRACT_ID> <METHOD_NAME> empty-args prepaid-gas '<GAS>' attached-deposit '<DEPOSIT>' sign-as <SIGNER_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefined

deploy

部署合约

sh
undefined
sh
undefined

Deploy without init call

部署无需初始化调用

near contract deploy <ACCOUNT_ID> use-file /path/to/contract.wasm without-init-call network-config <NETWORK> sign-with-keychain send
near contract deploy <ACCOUNT_ID> use-file /path/to/contract.wasm without-init-call network-config <NETWORK> sign-with-keychain send

Deploy with init call

部署并执行初始化调用

near contract deploy <ACCOUNT_ID> use-file /path/to/contract.wasm with-init-call <INIT_METHOD> json-args '{}' prepaid-gas '100 Tgas' attached-deposit '0 NEAR' network-config <NETWORK> sign-with-keychain send
undefined
near contract deploy <ACCOUNT_ID> use-file /path/to/contract.wasm with-init-call <INIT_METHOD> json-args '{}' prepaid-gas '100 Tgas' attached-deposit '0 NEAR' network-config <NETWORK> sign-with-keychain send
undefined

inspect

检查合约

sh
near contract inspect <CONTRACT_ID> network-config <NETWORK> now
sh
near contract inspect <CONTRACT_ID> network-config <NETWORK> now

verify

验证合约

sh
near contract verify deployed-at <CONTRACT_ID> network-config <NETWORK> now
sh
near contract verify deployed-at <CONTRACT_ID> network-config <NETWORK> now

download-abi

下载ABI

sh
near contract download-abi <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> now
sh
near contract download-abi <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> now

download-wasm

下载Wasm

sh
near contract download-wasm <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> now
sh
near contract download-wasm <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> now

view-storage

查看存储

sh
undefined
sh
undefined

View all storage as JSON

以JSON格式查看所有存储

near contract view-storage <CONTRACT_ID> all as-json network-config <NETWORK> now
near contract view-storage <CONTRACT_ID> all as-json network-config <NETWORK> now

View storage filtered by key prefix (string)

以JSON格式查看指定前缀的存储(字符串)

near contract view-storage <CONTRACT_ID> keys-start-with-string '<PREFIX>' as-json network-config <NETWORK> now
near contract view-storage <CONTRACT_ID> keys-start-with-string '<PREFIX>' as-json network-config <NETWORK> now

View storage filtered by key prefix (base64)

以JSON格式查看指定前缀的存储(Base64)

near contract view-storage <CONTRACT_ID> keys-start-with-bytes-as-base64 '<BASE64_PREFIX>' as-json network-config <NETWORK> now

---
near contract view-storage <CONTRACT_ID> keys-start-with-bytes-as-base64 '<BASE64_PREFIX>' as-json network-config <NETWORK> now

---

transaction
Commands

transaction
命令

view-status

查看交易状态

sh
near transaction view-status <TX_HASH> network-config <NETWORK>
sh
near transaction view-status <TX_HASH> network-config <NETWORK>

reconstruct-transaction

重构交易

sh
near transaction reconstruct-transaction <TX_HASH> network-config <NETWORK>
sh
near transaction reconstruct-transaction <TX_HASH> network-config <NETWORK>

sign-transaction

签署交易

sh
near transaction sign-transaction '<UNSIGNED_TX_BASE64>' network-config <NETWORK> sign-with-keychain send
sh
near transaction sign-transaction '<UNSIGNED_TX_BASE64>' network-config <NETWORK> sign-with-keychain send

send-signed-transaction

发送已签名交易

sh
near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config <NETWORK>
sh
near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config <NETWORK>

print-transaction

打印交易

sh
undefined
sh
undefined

Print signed transaction fields

打印已签名交易字段

near transaction print-transaction signed '<SIGNED_TX_BASE64>'
near transaction print-transaction signed '<SIGNED_TX_BASE64>'

Print unsigned transaction fields

打印未签名交易字段

near transaction print-transaction unsigned '<UNSIGNED_TX_BASE64>'
undefined
near transaction print-transaction unsigned '<UNSIGNED_TX_BASE64>'
undefined

send-meta-transaction

发送元交易

sh
near transaction send-meta-transaction '<SIGNED_DELEGATE_BASE64>' network-config <NETWORK>

sh
near transaction send-meta-transaction '<SIGNED_DELEGATE_BASE64>' network-config <NETWORK>

config
Commands

config
命令

show-connections

查看连接配置

sh
near config show-connections
sh
near config show-connections

add-connection

添加连接配置

sh
near config add-connection --network-name <NETWORK_NAME> --connection-name <CONNECTION_NAME> --rpc-url <RPC_URL> --wallet-url <WALLET_URL> --explorer-transaction-url <EXPLORER_TX_URL> [--rpc-api-key '<API_KEY>'] [--linkdrop-account-id <LINKDROP_ID>] [--faucet-url <FAUCET_URL>] [--meta-transaction-relayer-url <RELAYER_URL>]
sh
near config add-connection --network-name <NETWORK_NAME> --connection-name <CONNECTION_NAME> --rpc-url <RPC_URL> --wallet-url <WALLET_URL> --explorer-transaction-url <EXPLORER_TX_URL> [--rpc-api-key '<API_KEY>'] [--linkdrop-account-id <LINKDROP_ID>] [--faucet-url <FAUCET_URL>] [--meta-transaction-relayer-url <RELAYER_URL>]

delete-connection

删除连接配置

sh
near config delete-connection <CONNECTION_NAME>

sh
near config delete-connection <CONNECTION_NAME>

Common Patterns (Cookbook)

常用模式(速查手册)

Quick-reference one-liners for the most frequent tasks. Substitute placeholders with real values.
最常用操作的单行命令速查,将占位符替换为实际值即可使用。

1. Check NEAR balance

1. 查看NEAR余额

sh
near tokens alice.near view-near-balance network-config mainnet now
sh
near tokens alice.near view-near-balance network-config mainnet now

2. Transfer NEAR tokens

2. 转账NEAR代币

sh
near tokens alice.near send-near bob.near '5 NEAR' network-config mainnet sign-with-keychain send
sh
near tokens alice.near send-near bob.near '5 NEAR' network-config mainnet sign-with-keychain send

3. View account details

3. 查看账户详情

sh
near account view-account-summary alice.near network-config mainnet now
sh
near account view-account-summary alice.near network-config mainnet now

4. List access keys

4. 列出访问密钥

sh
near account list-keys alice.near network-config mainnet now
sh
near account list-keys alice.near network-config mainnet now

5. Send fungible tokens

5. 转账 fungible 代币

sh
near tokens alice.near send-ft usdt.tether-token.near bob.near '10 USDT' memo '' network-config mainnet sign-with-keychain send
sh
near tokens alice.near send-ft usdt.tether-token.near bob.near '10 USDT' memo '' network-config mainnet sign-with-keychain send

6. View FT balance

6. 查看FT余额

sh
near tokens alice.near view-ft-balance usdt.tether-token.near network-config mainnet now
sh
near tokens alice.near view-ft-balance usdt.tether-token.near network-config mainnet now

7. Call a view-only contract method

7. 调用只读合约方法

sh
near contract call-function as-read-only wrap.near ft_balance_of json-args '{"account_id":"alice.near"}' network-config mainnet now
sh
near contract call-function as-read-only wrap.near ft_balance_of json-args '{"account_id":"alice.near"}' network-config mainnet now

8. Call a state-changing contract method

8. 调用改变状态的合约方法

sh
near contract call-function as-transaction wrap.near ft_transfer json-args '{"receiver_id":"bob.near","amount":"1000000000000000000000000"}' prepaid-gas '100 Tgas' attached-deposit '1 yoctoNEAR' sign-as alice.near network-config mainnet sign-with-keychain send
sh
near contract call-function as-transaction wrap.near ft_transfer json-args '{"receiver_id":"bob.near","amount":"1000000000000000000000000"}' prepaid-gas '100 Tgas' attached-deposit '1 yoctoNEAR' sign-as alice.near network-config mainnet sign-with-keychain send

9. Stake NEAR with a validator

9. 向验证者质押NEAR

sh
near staking delegation alice.near deposit-and-stake '10 NEAR' aurora.pool.near network-config mainnet sign-with-keychain send
sh
near staking delegation alice.near deposit-and-stake '10 NEAR' aurora.pool.near network-config mainnet sign-with-keychain send

10. Unstake from a validator

10. 从验证者处解锁质押

sh
near staking delegation alice.near unstake-all aurora.pool.near network-config mainnet sign-with-keychain send
sh
near staking delegation alice.near unstake-all aurora.pool.near network-config mainnet sign-with-keychain send

11. Withdraw unstaked NEAR (after ~2 epoch wait)

11. 提取已解锁的NEAR(等待约2个纪元后)

sh
near staking delegation alice.near withdraw-all aurora.pool.near network-config mainnet sign-with-keychain send
sh
near staking delegation alice.near withdraw-all aurora.pool.near network-config mainnet sign-with-keychain send

12. Create a testnet account (faucet-funded)

12. 创建测试网账户(水龙头出资)

sh
near account create-account sponsor-by-faucet-service myaccount.testnet autogenerate-new-keypair save-to-keychain network-config testnet create
sh
near account create-account sponsor-by-faucet-service myaccount.testnet autogenerate-new-keypair save-to-keychain network-config testnet create

13. Create a sub-account (self-funded)

13. 创建子账户(自行出资)

sh
near account create-account fund-myself sub.alice.testnet '1 NEAR' autogenerate-new-keypair save-to-keychain sign-as alice.testnet network-config testnet sign-with-keychain send
sh
near account create-account fund-myself sub.alice.testnet '1 NEAR' autogenerate-new-keypair save-to-keychain sign-as alice.testnet network-config testnet sign-with-keychain send

14. Deploy a contract

14. 部署合约

sh
near contract deploy mycontract.testnet use-file ./contract.wasm without-init-call network-config testnet sign-with-keychain send
sh
near contract deploy mycontract.testnet use-file ./contract.wasm without-init-call network-config testnet sign-with-keychain send

15. Delete an access key

15. 删除访问密钥

sh
near account delete-keys alice.testnet public-keys ed25519:<PUBKEY_TO_REMOVE> network-config testnet sign-with-keychain send
sh
near account delete-keys alice.testnet public-keys ed25519:<PUBKEY_TO_REMOVE> network-config testnet sign-with-keychain send

16. Add a full-access key

16. 添加全权限密钥

sh
near account add-key alice.testnet grant-full-access use-manually-provided-public-key ed25519:<NEW_PUBKEY> network-config testnet sign-with-keychain send

sh
near account add-key alice.testnet grant-full-access use-manually-provided-public-key ed25519:<NEW_PUBKEY> network-config testnet sign-with-keychain send

Offline Mode and Scripting Tips

离线模式与脚本编写技巧

Offline signing workflow (air-gapped / two-machine)

离线签署工作流(离线环境/双机模式)

sh
undefined
sh
undefined

Machine A (offline): produce signed tx in base64 without broadcasting

机器A(离线):生成Base64格式的已签名交易,不广播

near --offline tokens alice.near send-near bob.near '1 NEAR' network-config mainnet sign-with-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' display
near --offline tokens alice.near send-near bob.near '1 NEAR' network-config mainnet sign-with-seed-phrase '<SEED_PHRASE>' --seed-phrase-hd-path 'm/44'"'"'/397'"'"'/0'"'"'' display

Machine B (online): broadcast the base64 tx

机器B(在线):广播Base64格式的交易

near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefined
near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefined

sign-later workflow

延迟签署工作流

sh
undefined
sh
undefined

Step 1: produce unsigned base64 tx

步骤1:生成Base64格式的未签名交易

near tokens alice.near send-near bob.near '1 NEAR' network-config mainnet sign-later
near tokens alice.near send-near bob.near '1 NEAR' network-config mainnet sign-later

Step 2: sign it (outputs signed base64)

步骤2:签署交易(输出Base64格式的已签名交易)

near transaction sign-transaction '<UNSIGNED_TX_BASE64>' network-config mainnet sign-with-keychain display
near transaction sign-transaction '<UNSIGNED_TX_BASE64>' network-config mainnet sign-with-keychain display

Step 3: broadcast

步骤3:广播交易

near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefined
near transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefined

Scripting tips

脚本编写技巧

  • Always add
    --quiet
    to suppress progress output in scripts
  • Always quote amounts:
    '1 NEAR'
    ,
    '0.5 NEAR'
    ,
    '1 yoctoNEAR'
  • Seed phrase HD path shell escaping:
    'm/44'"'"'/397'"'"'/0'"'"''
  • Use
    display
    instead of
    send
    to inspect signed tx before broadcasting

  • 脚本编写时始终添加
    --quiet
    以抑制进度输出
  • 金额需始终加引号:
    '1 NEAR'
    ,
    '0.5 NEAR'
    ,
    '1 yoctoNEAR'
  • 助记词HD路径的Shell转义:
    'm/44'"'"'/397'"'"'/0'"'"''
  • 广播前使用
    display
    替代
    send
    以检查已签名交易

Key Format Reference

密钥格式参考

ItemFormatExample
Public key
ed25519:<BASE58>
ed25519:8h7kFK4...
Private key
ed25519:<BASE58>
ed25519:2qM8v3N...
Transaction hash44-char base58
F3eZmht...
Named account
name.near
/
name.testnet
alice.near
Implicit account64-char lowercase hex
a4b05ef3...
Standard HD path
m/44'/397'/0'
NEAR BIP44
Ledger HD path
m/44'/397'/0'/0'/N'
5-component required for Ledger

格式示例
公钥
ed25519:<BASE58>
ed25519:8h7kFK4...
私钥
ed25519:<BASE58>
ed25519:2qM8v3N...
交易哈希44位Base58
F3eZmht...
命名账户
name.near
/
name.testnet
alice.near
隐式账户64位小写十六进制
a4b05ef3...
标准HD路径
m/44'/397'/0'
NEAR BIP44标准路径
Ledger HD路径
m/44'/397'/0'/0'/N'
Ledger需使用5段路径

Common Errors

常见错误

ErrorLikely cause / fix
"Account does not exist"Wrong network, or account not yet funded
"Access key not found"Use
sign-with-legacy-keychain
or
sign-with-seed-phrase
"Exceeded prepaid gas"Increase gas:
'300 Tgas'
FT transfer fails silentlyFT
ft_transfer
requires
attached-deposit '1 yoctoNEAR'
"Method not found"Check method name with
near contract inspect
Seed phrase HD path errorEscape single quotes:
'm/44'"'"'/397'"'"'/0'"'"''
错误信息可能原因/修复方法
"Account does not exist"网络选择错误,或账户尚未获得资金
"Access key not found"使用
sign-with-legacy-keychain
sign-with-seed-phrase
"Exceeded prepaid gas"增加Gas限额:
'300 Tgas'
FT转账无响应FT的
ft_transfer
方法需要附加
attached-deposit '1 yoctoNEAR'
"Method not found"使用
near contract inspect
检查方法名称是否正确
助记词HD路径错误转义单引号:
'm/44'"'"'/397'"'"'/0'"'"''