bitcoin-cli RPC 命令总结

当我们安装好bitcoin客户端之后,会自己在家目录下面生成一个.bitcoin文件,然后我们可以在这个目录下面建议一个配置文件,形如:

rpcuser=rpc
rpcpassword=xxxxxxx
rpcport=18332
daemon=1
server=1
testnet=1
whitelist=1.1.1.1
rpcallowip=1.1.1.1

使用bitcoin-cli help可以看到会输出如下命令:

== Blockchain ==
getbestblockhash
getblock "blockhash" ( verbose )
getblockchaininfo
getblockcount
getblockhash height
getblockheader "hash" ( verbose )
getchaintips
getchaintxstats ( nblocks blockhash )
getdifficulty
getmempoolancestors txid (verbose)
getmempooldescendants txid (verbose)
getmempoolentry txid
getmempoolinfo
getrawmempool ( verbose )
gettxout "txid" n ( include_mempool )
gettxoutproof ["txid",...] ( blockhash )
gettxoutsetinfo
preciousblock "blockhash"
pruneblockchain
verifychain ( checklevel nblocks )
verifytxoutproof "proof"

== Control ==
getinfo
getmemoryinfo
help ( "command" )
stop
uptime

== Generating ==
generate nblocks ( maxtries )
generatetoaddress nblocks address (maxtries)

== Mining ==
getblocktemplate ( TemplateRequest )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction <txid> <priority delta> <fee delta>
submitblock "hexdata" ( "jsonparametersobject" )

== Network ==
addnode "node" "add|remove|onetry"
clearbanned
disconnectnode "[address]" [nodeid]
getaddednodeinfo ( "node" )
getconnectioncount
getexcessiveblock
getnettotals
getnetworkinfo
getpeerinfo
listbanned
ping
setban "subnet" "add|remove" (bantime) (absolute)
setexcessiveblock blockSize
setnetworkactive true|false

== Omni layer (configuration) ==
whc_setautocommit flag

== Omni layer (data retrieval) ==
whc_getactivecrowd address
whc_getallbalancesforaddress "address"
whc_getallbalancesforid propertyid
whc_getbalance "address" propertyid
whc_getbalanceshash propertyid
whc_getcrowdsale propertyid ( verbose )
whc_getcurrentconsensushash
whc_getgrants propertyid
whc_getinfo
whc_getpayload "txid"
whc_getproperty propertyid
whc_getseedblocks startblock endblock
whc_getsto "txid" "recipientfilter"
whc_gettransaction "txid"
whc_listblocktransactions index
whc_listpendingtransactions ( "address" )
whc_listproperties
whc_listtransactions ( "address" count skip startblock endblock )

== Omni layer (payload creation) ==
whc_createpayload_burnbch
whc_createpayload_changeissuer propertyid
whc_createpayload_closecrowdsale propertyid
whc_createpayload_grant propertyid "amount" ( "memo" )
whc_createpayload_issuancecrowdsale ecosystem type previousid "category" "subcategory" "name" "url" "data" propertyiddesired tokensperunit deadline earlybonus issuerpercentage amount
whc_createpayload_issuancefixed ecosystem type previousid "category" "subcategory" "name" "url" "data" "amount"
whc_createpayload_issuancemanaged ecosystem type previousid "category" "subcategory" "name" "url" "data"
whc_createpayload_particrowdsale "amount"
whc_createpayload_revoke propertyid "amount" ( "memo" )
whc_createpayload_sendall ecosystem
whc_createpayload_simplesend propertyid "amount"
whc_createpayload_sto propertyid "amount" ( distributionproperty )

== Omni layer (raw transactions) ==
whc_createrawtx_change "rawtx" "prevtxs" "destination" fee ( position )
whc_createrawtx_input "rawtx" "txid" n
whc_createrawtx_opreturn "rawtx" "payload"
whc_createrawtx_reference "rawtx" "destination" ( amount )
whc_decodetransaction "rawtx" ( "prevtxs" height )

== Omni layer (transaction creation) ==
whc_burnbchgetwhc "amount" redeemaddress
whc_particrowsale "fromaddress" "toaddress" "amount" ( "redeemaddress" "referenceamount" )
whc_send "fromaddress" "toaddress" propertyid "amount" ( "redeemaddress" "referenceamount" )
whc_sendall "fromaddress" "toaddress" ecosystem ( "redeemaddress" "referenceamount" )
whc_sendchangeissuer "fromaddress" "toaddress" propertyid
whc_sendclosecrowdsale "fromaddress" propertyid
whc_sendgrant "fromaddress" "toaddress" propertyid "amount" ( "memo" )
whc_sendissuancecrowdsale "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data" propertyiddesired tokensperunit deadline earlybonus undefine totalNumber
whc_sendissuancefixed "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data" "totalNumber"
whc_sendissuancemanaged "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data"
whc_sendrawtx "fromaddress" "rawtransaction" ( "referenceaddress" "redeemaddress" "referenceamount" )
whc_sendrevoke "fromaddress" propertyid "amount" ( "memo" )
whc_sendsto "fromaddress" propertyid "amount" ( "redeemaddress" distributionproperty )

== Rawtransactions ==
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime )
decoderawtransaction "hexstring"
decodescript "hexstring"
fundrawtransaction "hexstring" ( options )
getrawtransaction "txid" ( verbose )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )

== Util ==
createmultisig nrequired ["key",...]
estimatefee nblocks
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"

== Wallet ==
abandontransaction "txid"
addmultisigaddress nrequired ["key",...] ( "account" )
backupwallet "destination"
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "address"
getaccountaddress "account"
getaddressesbyaccount "account"
getbalance ( "account" minconf include_watchonly )
getnewaddress ( "account" )
getrawchangeaddress
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "address" ( minconf )
gettransaction "txid" ( include_watchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan p2sh )
importmulti "requests" "options"
importprivkey "bitcoinprivkey" ( "label" ) ( rescan )
importprunedfunds
importpubkey "pubkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf include_watchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf include_empty include_watchonly)
listreceivedbyaddress ( minconf include_empty include_watchonly)
listsinceblock ( "blockhash" target_confirmations include_watchonly)
listtransactions ( "account" count skip include_watchonly)
listunspent ( minconf maxconf  ["addresses",...] [include_unsafe] )
listwallets
lockunspent unlock ([{"txid":"txid","vout":n},...])
move "fromaccount" "toaccount" amount ( minconf "comment" )
removeprunedfunds "txid"
sendfrom "fromaccount" "toaddress" amount ( minconf "comment" "comment_to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" ["address",...] )
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount )
setaccount "address" "account"
settxfee amount
signmessage "address" "message"

一些常用命令的解释

  1. bitcoin-cli getinfo获得比特币核心客户端状态的信息
  2. bitcoin-cli getbalance命令将显示钱包当前的所有地址的余额总和
  3. bitcoin-cli listunspent查看我们钱包中所有剩余的从之前交易中已确认的支出;
  4. bitcoin-cli createrawtransaction '[{"txid":"myid","vout":0}]' '{"address":0.01}'该命令用来创建交易,可以根据 listunspent 获取它的 txid ,amount 的数值不能太大,否则会提示昂贵的交易费。执行完成之后会生成一个 hexString,用来验证交易时使用。
  5. bitcoin-cli signrawtransaction "hexstring" ‘[{"txid":"id","vout":n, "amount":value,"scriptPubKey":"hex","redeemScript":"hex"},...]’ ‘["privatekey1",...]’ sighashtype该命令用来签名交易,注意:amount 应该是 listunspent 反应的 amount 的值,scriptPubKey 也是 listunspent 中的 scriptPubKey ,sighashtype 的默认值是 all,可以不写,redeemScript 是多重签名验证,没有特殊要求可以不写。执行完成之后会生成一个 signedhex 的签名验证码。
  6. bitcoin-cli sendrawtransaction "signedhex"该命令用来发送交易。
  7. bitcoin-cli walletpassphrase 密码 时间 walletpassphrase命令需要两个参数——密码,和多久钱包会再次被自动锁定的秒数数字(计时器)。该命令是用来解锁钱包的,执行完成什么也不会输出,代表解锁完成。
  8. bitcoin-cli dumpprivkey "address"该命令用来获取 privateKey,在第五步中会需要。

至此,一个简单的交易过程结束。

  • 其他命令
  1. 探索及解码交易
    • gettransaction 命令探索本钱包前面列出的入账交易;
      • bitcoin-cli gettransaction 交易ID
    • getrawtransaction命令获取交易的原始数据
      • bitcoin-cli getrawtransaction 交易ID
    • decoderawtransaction命令解码交易的原始数据,输出json格式
      • bitcoin-cli decoderawtransaction 交易的原始数据
  2. 探索区块
    • getblock命令,把区块的哈希值作为参数来查询对应的区块。
      • bitcoin-cli getblock 区块哈希
    • getblockhash命令通过区块高度来检索一个区块的哈希;
      • bitcoin-cli getblockhash 区块高度
  3. 基于UTXO的建立,签名与提交
    • listunspent命令去查看我们钱包中所有剩余的从之前交易中已确认的支出;
      • bitcoin-cli listunspent
    • gettxout 命令来得到未花费的输出的详细细节。
      • bitcoin-cli gettxout 交易ID 0
  4. 钱包地址及接收交易
    • bitcoin-cli getnewaddress ; 获取新的地址
    • 整个钱包接收到的交易可以通过使用listtransactions命令展示出来:
      • bitcoin-cli listtransactions;
    • 询问bitcoind客户端此地址已经接收到的比特币数额,以及指定该数额要被加到余额中所需要的确认数;
      • bitcoin-cli getreceivedbyaddress 钱包地址 确认数;
    • 使用getaddressesbyaccount命令列出整个钱包的所有地址
      • bitcoin-cli getaddressesbyaccount ""
    • getbalance命令将显示钱包当前的所有地址的余额总和
      • bitcoin-cli getbalance

RPC命令

命令: getblocktemplate

If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.
It returns data needed to construct a block to work on.
For full specification, see BIPs 22, 23, 9, and 145:
    https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki
    https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
    https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes
    https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki

Arguments:
1. template_request         (json object, optional) A json object in the following spec
     {
       "mode":"template"    (string, optional) This must be set to "template", "proposal" (see BIP 23), or omitted
       "capabilities":[     (array, optional) A list of strings
           "support"          (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'
           ,...
       ]
     }


Result:
{
  "version" : n,                    (numeric) The preferred block version
  "previousblockhash" : "xxxx",     (string) The hash of current highest block
  "transactions" : [                (array) contents of non-coinbase transactions that should be included in the next block
      {
         "data" : "xxxx",             (string) transaction data encoded in hexadecimal (byte-for-byte)
         "txid" : "xxxx",             (string) transaction id encoded in little-endian hexadecimal
         "hash" : "xxxx",             (string) hash encoded in little-endian hexadecimal (including witness data)
         "depends" : [                (array) array of numbers 
             n                          (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is
             ,...
         ],
         "fee": n,                    (numeric) difference in value between transaction inputs and outputs (in Satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one
         "sigops" : n,                (numeric) total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero
         "required" : true|false      (boolean) if provided and true, this transaction must be in the final block
      }
      ,...
  ],
  "coinbaseaux" : {                 (json object) data that should be included in the coinbase's scriptSig content
      "flags" : "xx"                  (string) key name is to be ignored, and value included in scriptSig
  },
  "coinbasevalue" : n,              (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in Satoshis)
  "coinbasetxn" : { ... },          (json object) information for coinbase transaction
  "target" : "xxxx",                (string) The hash target
  "mintime" : xxx,                  (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)
  "mutable" : [                     (array of string) list of ways the block template may be changed 
     "value"                          (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
     ,...
  ],
  "noncerange" : "00000000ffffffff",(string) A range of valid nonces
  "sigoplimit" : n,                 (numeric) limit of sigops in blocks
  "sizelimit" : n,                  (numeric) limit of block size
  "curtime" : ttt,                  (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)
  "bits" : "xxxxxxxx",              (string) compressed target of next block
  "height" : n                      (numeric) The height of the next block
}

命令:getmininginfo

getmininginfo

Returns a json object containing mining-related information.
Result:
{
  "blocks": nnn,             (numeric) The current block
  "currentblocksize": nnn,   (numeric) The last block size
  "currentblocktx": nnn,     (numeric) The last block transaction
  "difficulty": xxx.xxxxx    (numeric) The current difficulty
  "errors": "..."            (string) Current errors
  "networkhashps": nnn,      (numeric) The network hashes per second
  "pooledtx": n              (numeric) The size of the mempool
  "chain": "xxxx",           (string) current network name as defined in BIP70 (main, test, regtest)
}

命令:getnetworkhashps

getnetworkhashps ( nblocks height )

Returns the estimated network hashes per second based on the last n blocks.
Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.
Pass in [height] to estimate the network speed at the time when a certain block was found.

Arguments:
1. nblocks     (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.
2. height      (numeric, optional, default=-1) To estimate at the time of the given height.

Result:
x             (numeric) Hashes per second estimated

命令: prioritisetransaction

prioritisetransaction <txid> <priority delta> <fee delta>
Accepts the transaction into mined blocks at a higher (or lower) priority

Arguments:
1. "txid"       (string, required) The transaction id.
2. priority_delta (numeric, required) The priority to add or subtract.
                  The transaction selection algorithm considers the tx as it would have a higher priority.
                  (priority of a transaction is calculated: coinage * value_in_satoshis / txsize) 
3. fee_delta      (numeric, required) The fee value (in satoshis) to add (or subtract, if negative).
                  The fee is not actually paid, only the algorithm for selecting transactions into a block
                  considers the transaction as it would have paid a higher (or lower) fee.

Result:
true              (boolean) Returns true

命令:submitblock

"submitblock ""hexdata"" ( ""jsonparametersobject"" )

Attempts to submit new block to network.
The 'jsonparametersobject' parameter is currently ignored.
See https://en.bitcoin.it/wiki/BIP_0022 for full specification.

Arguments
1. ""hexdata""        (string, required) the hex-encoded block data to submit
2. ""parameters""     (string, optional) object of optional parameters
    {
      ""workid"" : ""id""    (string, optional) if the server provided a workid, it MUST be included with submissions
    }

Result:"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,440评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,814评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,427评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,710评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,625评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,014评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,511评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,162评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,311评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,262评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,278评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,989评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,583评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,664评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,904评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,274评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,856评论 2 339