Skip to main content

getblock

Overview

The 'getblock ' RPC Method retrieve detailed information about a specific block in the blockchain

Request

wget --no-check-certificate --quiet \
--method POST \
--timeout=0 \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--header 'X-CoinAPI-Key: 4303fb63-adec-42dc-b571-74bc2f2a5167' \
--body-data '{"jsonrpc":"2.0","id":1,"method":"getblock","params": [ ]}' \
'https://bitcoin-mainnet.node.coinapi.io'

Request Parameters

blockhash (string, required): The unique identifier of the block you want to retrieve information about. verbosity (numeric, optional, default = 1): Defines the level of detail in the response. It can be set to 0 for hex-encoded data, 1 for a JSON object, and 2 for a JSON object inclusive of transaction data.

Response

{
"result": null,
"error": {
"code": -1,
"message": "getblock \"blockhash\" ( verbosity )\n\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\nIf verbosity is 1, returns an Object with information about block <hash>.\nIf verbosity is 2, returns an Object with information about block <hash> and information about each transaction.\nIf verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n\nArguments:\n1. blockhash (string, required) The block hash\n2. verbosity (numeric, optional, default=1) 0 for hex-encoded data, 1 for a JSON object, 2 for JSON object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs\n\nResult (for verbosity = 0):\n\"hex\" (string) A string that is serialized, hex-encoded data for block 'hash'\n\nResult (for verbosity = 1):\n{ (json object)\n \"hash\" : \"hex\", (string) the block hash (same as provided)\n \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n \"size\" : n, (numeric) The block size\n \"strippedsize\" : n, (numeric) The block size excluding witness data\n \"weight\" : n, (numeric) The block weight as defined in BIP 141\n \"height\" : n, (numeric) The block height or index\n \"version\" : n, (numeric) The block version\n \"versionHex\" : \"hex\", (string) The block version formatted in hexadecimal\n \"merkleroot\" : \"hex\", (string) The merkle root\n \"tx\" : [ (json array) The transaction ids\n \"hex\", (string) The transaction id\n ...\n ],\n \"time\" : xxx, (numeric) The block time expressed in UNIX epoch time\n \"mediantime\" : xxx, (numeric) The median block time expressed in UNIX epoch time\n \"nonce\" : n, (numeric) The nonce\n \"bits\" : \"hex\", (string) The bits\n \"difficulty\" : n, (numeric) The difficulty\n \"chainwork\" : \"hex\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n \"nTx\" : n, (numeric) The number of transactions in the block\n \"previousblockhash\" : \"hex\", (string, optional) The hash of the previous block (if available)\n \"nextblockhash\" : \"hex\" (string, optional) The hash of the next block (if available)\n}\n\nResult (for verbosity = 2):\n{ (json object)\n ..., Same output as verbosity = 1\n \"tx\" : [ (json array)\n { (json object)\n ..., The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result\n \"fee\" : n (numeric) The transaction fee in BTC, omitted if block undo data is not available\n },\n ...\n ]\n}\n\nResult (for verbosity = 3):\n{ (json object)\n ..., Same output as verbosity = 2\n \"tx\" : [ (json array)\n { (json object)\n \"vin\" : [ (json array)\n { (json object)\n ..., The same output as verbosity = 2\n \"prevout\" : { (json object) (Only if undo information is available)\n \"generated\" : true|false, (boolean) Coinbase or not\n \"height\" : n, (numeric) The height of the prevout\n \"value\" : n, (numeric) The value in BTC\n \"scriptPubKey\" : { (json object)\n \"asm\" : \"str\", (string) The asm\n \"hex\" : \"str\", (string) The hex\n \"address\" : \"str\", (string, optional) The Bitcoin address (only if a well-defined address exists)\n \"type\" : \"str\" (string) The type (one of: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_v1_taproot, witness_unknown)\n }\n }\n },\n ...\n ]\n },\n ...\n ]\n}\n\nExamples:\n> bitcoin-cli getblock \"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"\n> 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/\n"
},
"id": 1
}

For verbosity = 0

  • hex: A string representing the serialized, hex-encoded data for the block hash.

For verbosity = 1

  • hex: The block hash.
  • confirmations: The number of confirmations the block has, or -1 if the block is not part of the main chain.
  • size: The size of the block in bytes.
  • strippedsize: The size of the block excluding witness data.
  • weight: The block weight as defined in BIP 141.
  • height: The block's position or index in the blockchain.
  • version: The version of the block.
  • versionHex: The block version formatted as a hexadecimal string.
  • merkleroot: The merkle root of the block.
  • tx: An array containing the transaction IDs present in the block.
  • hex: The transaction ID.
  • time: The time the block was created, expressed in UNIX epoch time.
  • mediantime: The median time of the block, expressed in UNIX epoch time.
  • nonce: The number of transactions made by the sender prior to this one, encoded as a hexadecimal string.
  • bits: The value of the nBits field in the block header.
  • difficulty: The estimated computational work required to find this block compared to the work required to find block 0.
  • chainwork: The expected number of hashes required to produce the current chain.
  • nTx: The number of transactions included in the block.
  • previousblockhash: The hash of the block that precedes this one in the blockchain.
  • nextblockhash: The hash of the block that follows this one in the blockchain.
  • error: Any error messages that occurred during the request, if applicable.

For verbosity = 2

  • Returns the same data as verbosity level 1, but also includes detailed information about each transaction in the 'tx' array.