near-cli-rs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSKILL: 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 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.
nearRule: Always produce complete commands from through the final action token (, , , , etc.). Never omit .
nearsenddisplaynowcreatenetwork-config <NETWORK>Version: near-cli-rs v0.14+ (tested through v0.24)
用途:本文件用于大语言模型生成非交互式命令。当用户请求对应某个CLI操作时,在此处查找正确的语法,构建完整的单行命令,展示给用户确认后再执行。
near规则:始终生成从开始到最终操作令牌(、、、等)的完整命令。绝不能省略。
nearsenddisplaynowcreatenetwork-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 or
senddisplay - Account creation via faucet ends with
create - keyword is always required (even for view commands)
network-config
near [全局标志] <命令组> [实体参数] <子命令> [子参数] network-config <网络> [签名选项] [最终操作]- 查询类命令以以下结尾:|
now|at-block-height <N>at-block-hash <HASH> - 交易类命令以签名选项加或
send结尾display - 通过水龙头创建账户以结尾
create - 关键字必须始终添加(即使是查询类命令)
network-config
Global Flags
全局标志
| Flag | Effect |
|---|---|
| Create/sign tx without network access |
| Suppress progress output (recommended for scripting) |
| Print all RPC calls and their parameters |
| 标志 | 作用 |
|---|---|
| 无需网络连接即可创建/签署交易 |
| 抑制进度输出(脚本编写推荐使用) |
| 打印所有RPC调用及其参数 |
Networks and View Qualifiers
网络与查询限定符
| Item | Value |
|---|---|
| Built-in networks | |
| Custom network | any |
| View: latest block | |
| View: specific height | |
| View: specific hash | |
| 项 | 值 |
|---|---|
| 内置网络 | |
| 自定义网络 | 来自 |
| 查询:最新区块 | |
| 查询:指定区块高度 | |
| 查询:指定区块哈希 | |
Amount and Gas Formats
金额与Gas格式
| Asset | Format | Notes |
|---|---|---|
| NEAR | | Quoted, space before unit |
| yoctoNEAR | | Required deposit for many contract calls |
| Gas | | Default |
| FT amount | | Number + FT symbol, quoted |
| FT all | | Transfer entire balance |
| 资产 | 格式 | 说明 |
|---|---|---|
| NEAR | | 需加引号,单位前有空格 |
| yoctoNEAR | | 许多合约调用所需的最低押金 |
| Gas | | 默认值 |
| FT金额 | | 数字+FT符号,需加引号 |
| FT全部余额 | | 转账全部余额 |
Signing Options Reference
签名选项参考
Replace in any transaction command with one of:
<SIGNING_OPTION>| Option | Full syntax |
|---|---|
| OS keychain (recommended) | |
Legacy keychain ( | |
| Ledger hardware wallet | |
| Plaintext private key | |
| Access key file | |
| Seed phrase | |
| MPC | |
| Produce unsigned tx (sign later) | |
Replace with to print the signed transaction in base64 without broadcasting.
senddisplay将任意交易类命令中的替换为以下选项之一:
<SIGNING_OPTION>| 选项 | 完整语法 |
|---|---|
| 操作系统钥匙串(推荐) | |
旧版钥匙串( | |
| Ledger硬件钱包 | |
| 明文私钥 | |
| 访问密钥文件 | |
| 助记词 | |
| MPC | |
| 生成未签名交易(后续签名) | |
将替换为可打印Base64格式的已签名交易,而不广播至网络。
senddisplayaccount
Commands
accountaccount
命令
accountview-account-summary
查看账户摘要
sh
undefinedsh
undefinedCurrent 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>
undefinednear account view-account-summary <ACCOUNT_ID> network-config <NETWORK> at-block-hash <BLOCK_HASH>
undefinedimport-account
导入账户
sh
undefinedsh
undefinedUsing 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需要浏览器重定向——不适合非交互式使用
undefinedundefinedexport-account
导出账户
sh
undefinedsh
undefinedExport 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>
undefinednear account export-account <ACCOUNT_ID> using-private-key network-config <NETWORK>
undefinedcreate-account
创建账户
sh
undefinedsh
undefinedTestnet 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
undefinednear 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
undefineddelete-account
删除账户
sh
near account delete-account <ACCOUNT_ID> beneficiary <BENEFICIARY_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain sendsh
near account delete-account <ACCOUNT_ID> beneficiary <BENEFICIARY_ACCOUNT_ID> network-config <NETWORK> sign-with-keychain sendlist-keys
列出密钥
sh
near account list-keys <ACCOUNT_ID> network-config <NETWORK> nowsh
near account list-keys <ACCOUNT_ID> network-config <NETWORK> nowget-public-key
获取公钥
sh
undefinedsh
undefinedFrom 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'"
undefinednear account get-public-key from-ledger --seed-phrase-hd-path "m/44'/397'/0'/0'/1'"
undefinedadd-key
添加密钥
sh
undefinedsh
undefinedAdd 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
undefinednear 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
undefineddelete-keys
删除密钥
sh
near account delete-keys <ACCOUNT_ID> public-keys ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain sendsh
near account delete-keys <ACCOUNT_ID> public-keys ed25519:<PUBKEY> network-config <NETWORK> sign-with-keychain sendmanage-storage-deposit
管理存储押金
sh
undefinedsh
undefinedView 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
undefinednear account manage-storage-deposit <CONTRACT_ID> withdraw '<AMOUNT>' sign-as <ACCOUNT_ID> network-config <NETWORK> sign-with-keychain send
undefinedupdate-social-profile
更新社交资料
sh
undefinedsh
undefinedUpdate 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
tokenstokens
命令
tokensview-near-balance
查看NEAR余额
sh
near tokens <ACCOUNT_ID> view-near-balance network-config <NETWORK> nowsh
near tokens <ACCOUNT_ID> view-near-balance network-config <NETWORK> nowview-ft-balance
查看FT余额
sh
near tokens <ACCOUNT_ID> view-ft-balance <FT_CONTRACT_ID> network-config <NETWORK> nowsh
near tokens <ACCOUNT_ID> view-ft-balance <FT_CONTRACT_ID> network-config <NETWORK> nowview-nft-assets
查看NFT资产
sh
near tokens <ACCOUNT_ID> view-nft-assets <NFT_CONTRACT_ID> network-config <NETWORK> nowsh
near tokens <ACCOUNT_ID> view-nft-assets <NFT_CONTRACT_ID> network-config <NETWORK> nowsend-near
转账NEAR
sh
near tokens <SENDER_ACCOUNT_ID> send-near <RECEIVER_ACCOUNT_ID> '<AMOUNT>' network-config <NETWORK> sign-with-keychain sendsh
near tokens <SENDER_ACCOUNT_ID> send-near <RECEIVER_ACCOUNT_ID> '<AMOUNT>' network-config <NETWORK> sign-with-keychain sendsend-ft
转账FT
sh
undefinedsh
undefinedSend 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 sendsh
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 sendstaking
Commands
stakingstaking
命令
stakingvalidator-list
验证者列表
sh
near staking validator-list network-config <NETWORK>sh
near staking validator-list network-config <NETWORK>delegation
质押委托
sh
undefinedsh
undefinedView 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
contractcontract
命令
contractcall-function (view/read-only)
调用函数(查询/只读)
sh
undefinedsh
undefinedWith 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
undefinednear contract call-function as-read-only <CONTRACT_ID> <METHOD_NAME> base64-args '<BASE64>' network-config <NETWORK> now
undefinedcall-function (transaction/state-changing)
调用函数(交易/改变状态)
sh
undefinedsh
undefinedWith 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
undefinednear 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
undefineddeploy
部署合约
sh
undefinedsh
undefinedDeploy 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
undefinednear 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
undefinedinspect
检查合约
sh
near contract inspect <CONTRACT_ID> network-config <NETWORK> nowsh
near contract inspect <CONTRACT_ID> network-config <NETWORK> nowverify
验证合约
sh
near contract verify deployed-at <CONTRACT_ID> network-config <NETWORK> nowsh
near contract verify deployed-at <CONTRACT_ID> network-config <NETWORK> nowdownload-abi
下载ABI
sh
near contract download-abi <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> nowsh
near contract download-abi <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> nowdownload-wasm
下载Wasm
sh
near contract download-wasm <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> nowsh
near contract download-wasm <CONTRACT_ID> save-to-file <OUTPUT_FILE_PATH> network-config <NETWORK> nowview-storage
查看存储
sh
undefinedsh
undefinedView 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
transactiontransaction
命令
transactionview-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 sendsh
near transaction sign-transaction '<UNSIGNED_TX_BASE64>' network-config <NETWORK> sign-with-keychain sendsend-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
undefinedsh
undefinedPrint 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>'
undefinednear transaction print-transaction unsigned '<UNSIGNED_TX_BASE64>'
undefinedsend-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
configconfig
命令
configshow-connections
查看连接配置
sh
near config show-connectionssh
near config show-connectionsadd-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 nowsh
near tokens alice.near view-near-balance network-config mainnet now2. Transfer NEAR tokens
2. 转账NEAR代币
sh
near tokens alice.near send-near bob.near '5 NEAR' network-config mainnet sign-with-keychain sendsh
near tokens alice.near send-near bob.near '5 NEAR' network-config mainnet sign-with-keychain send3. View account details
3. 查看账户详情
sh
near account view-account-summary alice.near network-config mainnet nowsh
near account view-account-summary alice.near network-config mainnet now4. List access keys
4. 列出访问密钥
sh
near account list-keys alice.near network-config mainnet nowsh
near account list-keys alice.near network-config mainnet now5. 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 sendsh
near tokens alice.near send-ft usdt.tether-token.near bob.near '10 USDT' memo '' network-config mainnet sign-with-keychain send6. View FT balance
6. 查看FT余额
sh
near tokens alice.near view-ft-balance usdt.tether-token.near network-config mainnet nowsh
near tokens alice.near view-ft-balance usdt.tether-token.near network-config mainnet now7. 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 nowsh
near contract call-function as-read-only wrap.near ft_balance_of json-args '{"account_id":"alice.near"}' network-config mainnet now8. 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 sendsh
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 send9. 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 sendsh
near staking delegation alice.near deposit-and-stake '10 NEAR' aurora.pool.near network-config mainnet sign-with-keychain send10. Unstake from a validator
10. 从验证者处解锁质押
sh
near staking delegation alice.near unstake-all aurora.pool.near network-config mainnet sign-with-keychain sendsh
near staking delegation alice.near unstake-all aurora.pool.near network-config mainnet sign-with-keychain send11. 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 sendsh
near staking delegation alice.near withdraw-all aurora.pool.near network-config mainnet sign-with-keychain send12. 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 createsh
near account create-account sponsor-by-faucet-service myaccount.testnet autogenerate-new-keypair save-to-keychain network-config testnet create13. 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 sendsh
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 send14. Deploy a contract
14. 部署合约
sh
near contract deploy mycontract.testnet use-file ./contract.wasm without-init-call network-config testnet sign-with-keychain sendsh
near contract deploy mycontract.testnet use-file ./contract.wasm without-init-call network-config testnet sign-with-keychain send15. Delete an access key
15. 删除访问密钥
sh
near account delete-keys alice.testnet public-keys ed25519:<PUBKEY_TO_REMOVE> network-config testnet sign-with-keychain sendsh
near account delete-keys alice.testnet public-keys ed25519:<PUBKEY_TO_REMOVE> network-config testnet sign-with-keychain send16. 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 sendsh
near account add-key alice.testnet grant-full-access use-manually-provided-public-key ed25519:<NEW_PUBKEY> network-config testnet sign-with-keychain sendOffline Mode and Scripting Tips
离线模式与脚本编写技巧
Offline signing workflow (air-gapped / two-machine)
离线签署工作流(离线环境/双机模式)
sh
undefinedsh
undefinedMachine 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
undefinednear transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefinedsign-later workflow
延迟签署工作流
sh
undefinedsh
undefinedStep 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
undefinednear transaction send-signed-transaction '<SIGNED_TX_BASE64>' network-config mainnet
undefinedScripting tips
脚本编写技巧
- Always add to suppress progress output in scripts
--quiet - Always quote amounts: ,
'1 NEAR','0.5 NEAR''1 yoctoNEAR' - Seed phrase HD path shell escaping:
'm/44'"'"'/397'"'"'/0'"'"'' - Use instead of
displayto inspect signed tx before broadcastingsend
- 脚本编写时始终添加以抑制进度输出
--quiet - 金额需始终加引号:,
'1 NEAR','0.5 NEAR''1 yoctoNEAR' - 助记词HD路径的Shell转义:
'm/44'"'"'/397'"'"'/0'"'"'' - 广播前使用替代
display以检查已签名交易send
Key Format Reference
密钥格式参考
| Item | Format | Example |
|---|---|---|
| Public key | | |
| Private key | | |
| Transaction hash | 44-char base58 | |
| Named account | | |
| Implicit account | 64-char lowercase hex | |
| Standard HD path | | NEAR BIP44 |
| Ledger HD path | | 5-component required for Ledger |
| 项 | 格式 | 示例 |
|---|---|---|
| 公钥 | | |
| 私钥 | | |
| 交易哈希 | 44位Base58 | |
| 命名账户 | | |
| 隐式账户 | 64位小写十六进制 | |
| 标准HD路径 | | NEAR BIP44标准路径 |
| Ledger HD路径 | | Ledger需使用5段路径 |
Common Errors
常见错误
| Error | Likely cause / fix |
|---|---|
| "Account does not exist" | Wrong network, or account not yet funded |
| "Access key not found" | Use |
| "Exceeded prepaid gas" | Increase gas: |
| FT transfer fails silently | FT |
| "Method not found" | Check method name with |
| Seed phrase HD path error | Escape single quotes: |
| 错误信息 | 可能原因/修复方法 |
|---|---|
| "Account does not exist" | 网络选择错误,或账户尚未获得资金 |
| "Access key not found" | 使用 |
| "Exceeded prepaid gas" | 增加Gas限额: |
| FT转账无响应 | FT的 |
| "Method not found" | 使用 |
| 助记词HD路径错误 | 转义单引号: |