當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Bitcoin getblock用法及代碼示例


比特幣(Bitcoin) RPC Blockchain API中getblock的用法及代碼示例。

用法:

getblock "blockhash" ( verbosity )

如果 verbosity 為0,則返回已序列化的字符串,即塊‘hash’的hex-encoded數據。

如果 verbosity 為1,則返回一個對象,其中包含有關塊‘hash’的信息。

如果 verbosity 為2,則返回一個對象,其中包含有關塊‘hash’的信息以及有關每個事務的信息。

參數1 - blockhash

類型:字符串,必填

區塊哈希

參數2 - verbosity

類型:數字,可選,默認值= 1

0表示hex-encoded數據,1表示json對象,2表示帶有事務數據的json對象

返回結果(對於 verbosity = 0)

名稱

類型

描述

data

string

塊‘hash’的已序列化字符串hex-encoded數據。

返回結果(對於 verbosity = 1)

{
  "hash" : "hash",     (string) the block hash (same as provided)
  "confirmations" : n,   (numeric) The number of confirmations, or -1 if the block is not on the main chain
  "size" : n,            (numeric) The block size
  "strippedsize" : n,    (numeric) The block size excluding witness data
  "weight" : n           (numeric) The block weight as defined in BIP 141
  "height" : n,          (numeric) The block height or index
  "version" : n,         (numeric) The block version
  "versionHex" : "00000000", (string) The block version formatted in hexadecimal
  "merkleroot" : "xxxx", (string) The merkle root
  "tx" : [               (array of string) The transaction ids
     "transactionid"     (string) The transaction id
     ,...
  ],
  "time" : ttt,          (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)
  "mediantime" : ttt,    (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)
  "nonce" : n,           (numeric) The nonce
  "bits" : "1d00ffff", (string) The bits
  "difficulty" : x.xxx,  (numeric) The difficulty
  "chainwork" : "xxxx",  (string) Expected number of hashes required to produce the chain up to this block (in hex)
  "nTx" : n,             (numeric) The number of transactions in the block.
  "previousblockhash" : "hash",  (string) The hash of the previous block
  "nextblockhash" : "hash"       (string) The hash of the next block
}

返回結果(對於 verbosity = 2)

{
  ...,                     Same output as verbosity = 1.
  "tx" : [               (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 "tx" result.
         ,...
  ],
  ,...                     Same output as verbosity = 1.
}

示例

bitcoin-cli getblock "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

相關用法


注:本文由純淨天空篩選整理自bitcoin.org大神的英文原創作品 Bitcoin getblock。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。