美文网首页以太坊
bitcoin-cli RPC 命令总结

bitcoin-cli RPC 命令总结

作者: wolf4j | 来源:发表于2018-09-07 17:49 被阅读421次

    当我们安装好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:"
    

    相关文章

      网友评论

        本文标题:bitcoin-cli RPC 命令总结

        本文链接:https://www.haomeiwen.com/subject/xmacgftx.html