bitcoin-cli RPC 命令總結(jié)

當我們安裝好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獲得比特幣核心客戶端狀態(tài)的信息
  2. bitcoin-cli getbalance命令將顯示錢包當前的所有地址的余額總和
  3. bitcoin-cli listunspent查看我們錢包中所有剩余的從之前交易中已確認的支出弃舒;
  4. bitcoin-cli createrawtransaction '[{"txid":"myid","vout":0}]' '{"address":0.01}'該命令用來創(chuàng)建交易鸽粉,可以根據(jù) listunspent 獲取它的 txid ,amount 的數(shù)值不能太大触机,否則會提示昂貴的交易費。執(zhí)行完成之后會生成一個 hexString儡首,用來驗證交易時使用。
  5. bitcoin-cli signrawtransaction "hexstring" ‘[{"txid":"id","vout":n, "amount":value,"scriptPubKey":"hex","redeemScript":"hex"},...]’ ‘["privatekey1",...]’ sighashtype該命令用來簽名交易蔬胯,注意:amount 應(yīng)該是 listunspent 反應(yīng)的 amount 的值,scriptPubKey 也是 listunspent 中的 scriptPubKey 笔宿,sighashtype 的默認值是 all犁钟,可以不寫泼橘,redeemScript 是多重簽名驗證,沒有特殊要求可以不寫炬灭。執(zhí)行完成之后會生成一個 signedhex 的簽名驗證碼。
  6. bitcoin-cli sendrawtransaction "signedhex"該命令用來發(fā)送交易重归。
  7. bitcoin-cli walletpassphrase 密碼 時間 walletpassphrase命令需要兩個參數(shù)——密碼米愿,和多久錢包會再次被自動鎖定的秒數(shù)數(shù)字(計時器)精居。該命令是用來解鎖錢包的屯耸,執(zhí)行完成什么也不會輸出腥放,代表解鎖完成编兄。
  8. bitcoin-cli dumpprivkey "address"該命令用來獲取 privateKey,在第五步中會需要灭红。

至此脓斩,一個簡單的交易過程結(jié)束证逻。

  • 其他命令
  1. 探索及解碼交易
    • gettransaction 命令探索本錢包前面列出的入賬交易;
      • bitcoin-cli gettransaction 交易ID
    • getrawtransaction命令獲取交易的原始數(shù)據(jù)
      • bitcoin-cli getrawtransaction 交易ID
    • decoderawtransaction命令解碼交易的原始數(shù)據(jù)香椎,輸出json格式
      • bitcoin-cli decoderawtransaction 交易的原始數(shù)據(jù)
  2. 探索區(qū)塊
    • getblock命令漱竖,把區(qū)塊的哈希值作為參數(shù)來查詢對應(yīng)的區(qū)塊。
      • bitcoin-cli getblock 區(qū)塊哈希
    • getblockhash命令通過區(qū)塊高度來檢索一個區(qū)塊的哈希畜伐;
      • bitcoin-cli getblockhash 區(qū)塊高度
  3. 基于UTXO的建立馍惹,簽名與提交
    • listunspent命令去查看我們錢包中所有剩余的從之前交易中已確認的支出;
      • bitcoin-cli listunspent
    • gettxout 命令來得到未花費的輸出的詳細細節(jié)玛界。
      • bitcoin-cli gettxout 交易ID 0
  4. 錢包地址及接收交易
    • bitcoin-cli getnewaddress ; 獲取新的地址
    • 整個錢包接收到的交易可以通過使用listtransactions命令展示出來:
      • bitcoin-cli listtransactions;
    • 詢問bitcoind客戶端此地址已經(jīng)接收到的比特幣數(shù)額万矾,以及指定該數(shù)額要被加到余額中所需要的確認數(shù);
      • bitcoin-cli getreceivedbyaddress 錢包地址 確認數(shù);
    • 使用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:"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市脚仔,隨后出現(xiàn)的幾起案子勤众,更是在濱河造成了極大的恐慌,老刑警劉巖鲤脏,帶你破解...
    沈念sama閱讀 206,839評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異吕朵,居然都是意外死亡猎醇,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,543評論 2 382
  • 文/潘曉璐 我一進店門努溃,熙熙樓的掌柜王于貴愁眉苦臉地迎上來硫嘶,“玉大人,你說我怎么就攤上這事梧税÷偌玻” “怎么了称近?”我有些...
    開封第一講書人閱讀 153,116評論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長哮塞。 經(jīng)常有香客問我刨秆,道長,這世上最難降的妖魔是什么衡未? 我笑而不...
    開封第一講書人閱讀 55,371評論 1 279
  • 正文 為了忘掉前任缓醋,我火速辦了婚禮绊诲,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘葫督。我一直安慰自己板惑,他們只是感情好,可當我...
    茶點故事閱讀 64,384評論 5 374
  • 文/花漫 我一把揭開白布洽胶。 她就那樣靜靜地躺著姊氓,像睡著了一般翔横。 火紅的嫁衣襯著肌膚如雪梗搅。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,111評論 1 285
  • 那天荡短,我揣著相機與錄音掘托,去河邊找鬼籍嘹。 笑死弯院,一個胖子當著我的面吹牛听绳,可吹牛的內(nèi)容都是我干的族淮。 我是一名探鬼主播,決...
    沈念sama閱讀 38,416評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼贴妻,長吁一口氣:“原來是場噩夢啊……” “哼名惩!你這毒婦竟也來了孕荠?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,053評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎个曙,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體呼寸,經(jīng)...
    沈念sama閱讀 43,558評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡对雪,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,007評論 2 325
  • 正文 我和宋清朗相戀三年瑟捣,在試婚紗的時候發(fā)現(xiàn)自己被綠了义郑。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,117評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖劫笙,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情填大,我是刑警寧澤,帶...
    沈念sama閱讀 33,756評論 4 324
  • 正文 年R本政府宣布圈浇,位于F島的核電站磷蜀,受9級特大地震影響百炬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜庶弃,卻給世界環(huán)境...
    茶點故事閱讀 39,324評論 3 307
  • 文/蒙蒙 一歇攻、第九天 我趴在偏房一處隱蔽的房頂上張望梆造。 院中可真熱鬧,春花似錦斧散、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,315評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至色迂,卻和暖如春手销,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,539評論 1 262
  • 我被黑心中介騙來泰國打工祸轮, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留适袜,地道東北人舷夺。 一個月前我還...
    沈念sama閱讀 45,578評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像疫萤,于是被迫代替她去往敵國和親耙册。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,877評論 2 345