带有 JSON-RPC 接口的基于命令行的守护进程 bitcoind 与比特币核心(Bicoin Core)绑定在一起。 一个允许用户发送 RPC 命令到 bitcoind 的简单程序 bitcoin-cli 也包含在比特币核心。

下面列出了 bitcoin v0.12.1 客户端 bitcoin-cli 所有(含隐藏分类)的 RPC 命令。

1. 帮助信息

$ bitcoin-cli -h # 显示帮助信息
Bitcoin Core RPC client version v0.12.1.0-f61a24e
比特币核心 RPC 客户端版本 v0.12.1.0-改源码后附加的字符串

Usage:
用法:共 3 种,[] 表示可以省略,单纯的使用 Options 选项不需要 bitcoind,而 help 和 <command> 都需要 bitcoind
  bitcoin-cli [options] <command> [params]  Send command to Bitcoin Core # 发送命令到比特币内核
  bitcoin-cli [options] help                List commands # 列出命令
  bitcoin-cli [options] help <command>      Get help for a command # 获取一条命令的帮助

Options:
选项:

  -?
       This help message
       该程序的帮助信息,同 -h-help 选项

  -conf=<file>
       Specify configuration file (default: bitcoin.conf)
       指定配置文件(默认:~/.bitcoin/bitcoin.conf)

  -datadir=<dir>
       Specify data directory
       指定数据目录

Chain selection options:
链选择选项(默认主网):

  -testnet
       Use the test chain
       使用公共测试链

  -regtest
       Enter regression test mode, which uses a special chain in which blocks
       can be solved instantly. This is intended for regression testing tools
       and app development.
       进入回归测试模式,使用一条特殊的链,可以立刻解决产块的问题。
       这是专门用于回归测试工具和应用程序开发的。

  -rpcconnect=<ip>
       Send commands to node running on <ip> (default: 127.0.0.1)
       发送命令到运行在 <ip> 上的节点(默认:127.0.0.1)

  -rpcport=<port>
       Connect to JSON-RPC on <port> (default: 8332 or testnet: 18332)
       连接到指定 <port> 上的 JSON-RPC(默认:8332 或 公共测试网:18332)

  -rpcwait
       Wait for RPC server to start
       等待 RPC 服务启动

  -rpcuser=<user>
       Username for JSON-RPC connections
       JSON-RPC 连接的用户名

  -rpcpassword=<pw>
       Password for JSON-RPC connections
       JSON-RPC 连接的密码

  -rpcclienttimeout=<n>
       Timeout during HTTP requests (default: 900)
       HTTP 请求的超时时间(默认:900s)

2. RPCs

注:需要 bitcoind 提供相关服务。 括号内的 ( 参数 ) 有默认值,可以省略。

$ bitcoin-cli help # 列出命令

== Blockchain | 区块链 ==
getbestblockhash # 获取最佳块哈希
getblock “hash” ( verbose ) # 获取指定区块信息
getblockchaininfo # 获取区块链信息
getblockcount # 获取当前的区块数
getblockhash index # 获取指定区块哈希
getblockheader “hash” ( verbose ) # 获取指定区块头信息
getchaintips # 获取区块链尖信息
getdifficulty # 获取当前挖矿难度
getmempoolinfo # 获取交易内存池信息
getrawmempool ( verbose ) # 获取内存池原始交易
gettxout “txid” n ( includemempool ) # 获取交易输出细节
gettxoutproof [“txid”,…] ( blockhash ) # 获取交易证明
gettxoutsetinfo # 获取交易输出集合信息
verifychain ( checklevel numblocks ) # 验证链
verifytxoutproof “proof” # 验证交易证明

== Control | 控制 ==
getinfo # 获取比特币核心信息
help ( “command” ) # 获取命令帮助信息
stop # 远程终止比特币核心服务

== Generating | 生成 ==
generate numblocks # 生成区块
getgenerate # 获取挖矿状态
setgenerate generate ( genproclimit ) # 挖矿开关

== Mining | 挖矿 ==
getblocktemplate ( “jsonrequestobject” ) # 获取区块模板
getmininginfo # 获取挖矿信息
getnetworkhashps ( blocks height ) # 获取网络算力
prioritisetransaction <txid> <priority delta> <fee delta> # 改变交易优先级
submitblock “hexdata” ( “jsonparametersobject” ) # 提交区块

== Network | 网络 ==
addnode “node” “add|remove|onetry” # 添加节点并执行操作
clearbanned # 清空黑名单
disconnectnode “node” # 断开与指定节点的连接
getaddednodeinfo dns ( “node” ) # 获取添加的节点信息
getconnectioncount # 获取连接数
getnettotals # 获取网络总流量
getnetworkinfo # 获取网络信息
getpeerinfo # 获取对端信息
listbanned # 列出黑名单
ping # ping 连接的节点
setban “ip(/netmask)” “add|remove” (bantime) (absolute) # 设置黑名单

== Rawtransactions | 原始交易 ==
createrawtransaction [{“txid”:”id”,”vout”:n},…] {“address”:amount,”data”:”hex”,…} ( locktime ) # 创建原始交易
decoderawtransaction “hexstring” # 解码原始交易
decodescript “hex” # 解码脚本
fundrawtransaction “hexstring” includeWatching # 资助原始交易
getrawtransaction “txid” ( verbose ) # 获取原始交易信息
sendrawtransaction “hexstring” ( allowhighfees ) # 发送原始交易
signrawtransaction “hexstring” ( [{“txid”:”id”,”vout”:n,”scriptPubKey”:”hex”,”redeemScript”:”hex”},…] [“privatekey1”,…] sighashtype ) # 签名原始交易

== Util | 实用 ==
createmultisig nrequired [“key”,…] # 创建多重签名
estimatefee nblocks # 估算交易费
estimatepriority nblocks # 估算交易优先级
estimatesmartfee nblocks # 智能估计交易费
estimatesmartpriority nblocks # 智能估计交易优先级
validateaddress “bitcoinaddress” # 验证地址
verifymessage “bitcoinaddress” “signature” “message” # 验证消息

== Hidden | 隐藏 ==
invalidateblock # 无效化区块
reconsiderblock # 再考虑区块
setmocktime # 设置 mocktime
resendwallettransactions # 再次发送钱包交易

== Wallet | 钱包 ==
abandontransaction “txid” # 放弃交易
addmultisigaddress nrequired [“key”,…] ( “account” ) # 添加多签地址
backupwallet “destination” # 备份钱包
dumpprivkey “bitcoinaddress” # 导出私钥
dumpwallet “filename” # 导出钱包
encryptwallet “passphrase” # 加密钱包
getaccount “bitcoinaddress” # (已过时)获取地址所属账户
getaccountaddress “account” # (已过时)获取账户收款地址
getaddressesbyaccount “account” # 获取某账户下所有地址
getbalance ( “account” minconf includeWatchonly ) # 获取余额
getnewaddress ( “account” ) # 获取新的地址
getrawchangeaddress # 获取原始交易找零地址
getreceivedbyaccount “account” ( minconf ) # (已过时)获取指定账户接收到的金额
getreceivedbyaddress “bitcoinaddress” ( minconf ) # 获取指定地址接收到的金额
gettransaction “txid” ( includeWatchonly ) # 获取交易信息
getunconfirmedbalance # 获取未确认的余额
getwalletinfo # 获取钱包信息
importaddress “address” ( “label” rescan p2sh ) # 导入地址或脚本
importprivkey “bitcoinprivkey” ( “label” rescan ) # 导入私钥
importpubkey “pubkey” ( “label” rescan ) # 导入公钥
importwallet “filename” # 导入钱包
keypoolrefill ( newsize ) # 再填充钥匙池
listaccounts ( minconf includeWatchonly) # (已过时)列出账户及其余额
listaddressgroupings # 列出地址分组
listlockunspent # 列出锁定的未花费交易输出
listreceivedbyaccount ( minconf includeempty includeWatchonly) # (已过时)列出账户接收金额
listreceivedbyaddress ( minconf includeempty includeWatchonly) # 列出地址接收金额
listsinceblock ( “blockhash” target-confirmations includeWatchonly) # 列从某区块开始的全部交易
listtransactions ( “account” count from includeWatchonly) # 列出交易
listunspent ( minconf maxconf [“address”,…] ) # 列出未花费交易输出
lockunspent unlock [{“txid”:”txid”,”vout”:n},…] # 加解锁未花费交易输出
move “fromaccount” “toaccount” amount ( minconf “comment” ) # (已过时)转账
sendfrom “fromaccount” “tobitcoinaddress” amount ( minconf “comment” “comment-to” ) # (已过时)从指定账户发送
sendmany “fromaccount” {“address”:amount,…} ( minconf “comment” [“address”,…] ) # 发送到多个地址
sendtoaddress “bitcoinaddress” amount ( “comment” “comment-to” subtractfeefromamount ) # 发送到指定地址
setaccount “bitcoinaddress” “account” # (已过时)设置地址关联账户
settxfee amount # 设置交易费
signmessage “bitcoinaddress” “message” # 签名消息
walletlock # 锁定钱包
walletpassphrase “passphrase” timeout # 解锁钱包数秒
walletpassphrasechange “oldpassphrase” “newpassphrase” # 更改钱包密码

参考链接