getblock - Bitcoin Cash

This method returns information about a block given its hash. Verbosity controls whether the block is returned as hex, as a JSON object, or as a JSON object with full transaction detail.

Parameters

ParameterTypeRequiredDescription
blockhashstringYesThe block hash
verbositynumericNo0 for hex, 1 for a JSON object, 2 for a JSON object with transaction data. Default 1

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getblock",
    "params": ["0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc", 1],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');
const { data } = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
  jsonrpc: '2.0', method: 'getblock',
  params: ['0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc', 1], id: 'getblock.io'
});
console.log(data.result.height, data.result.nTx);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getblock',
        'params': ["0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc", 1],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getblock",
            "params": ["0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc", 1],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "error": null,
    "id": "getblock.io",
    "result": {
        "hash": "0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc",
        "confirmations": 1197,
        "height": 684634,
        "version": 1073733632,
        "versionHex": "3fffe000",
        "merkleroot": "d14c9f467c4bdd5135837696150ab5f52f3f5043de324ca4e5766b195b9f8f37",
        "time": 1617180599,
        "mediantime": 1617176373,
        "nonce": 3669423616,
        "bits": "170cdf6f",
        "difficulty": 21865558044610.55,
        "chainwork": "00000000000000000000000000000000000000001b633a711a2334c78a29bb40",
        "nTx": 2815,
        "previousblockhash": "000000000000000001d3a318372df5d1eec54462a0d7471ae1cdf49838f793dd",
        "nextblockhash": "000000000000000000006d8e1eb870bd281b30ed621acf6b8d6af2a3c7ab61f1",
        "size": 1350854,
        "tx": [
            "10b54fd708ab2e5703979b4ba27ca0339882abc2062e77fbe51e625203a49642",
            "780791bb2d5a8ccda4b5a707967a8e15b412814852c58c77299e85579bb65587"
        ]
    }
}

Response Parameters

ParameterTypeDescription
errornull|objectError object when the call fails, otherwise null
idstringRequest identifier matching the request
resultobjectBlock object at the requested verbosity level

Result Object

FieldTypeDescription
hashstringBlock hash
confirmationsnumericConfirmations, or -1 if the block is not on the main chain
heightnumericBlock height
merklerootstringMerkle root of the block's transactions
timenumericBlock time as a Unix timestamp
nTxnumericNumber of transactions in the block
previousblockhashstringHash of the parent block
txarrayTransaction ids, or full transaction objects at verbosity 2

Use Cases

  • Block Explorers: Render block contents including transaction lists
  • Chain Indexing: Stream blocks sequentially into an off-chain database
  • Transaction Discovery: List every txid in a block at verbosity 1
  • Fee Analysis: Read full transaction detail at verbosity 2 for fee studies
  • Timestamp Mapping: Attach wall-clock time to a block by hash

Error Handling

Error CodeMessageDescription
-8Invalid parameterblockhash is not a valid 64-character hex string
-5Block not foundNo block with the given hash exists on this node
-32603Internal errorNode failed to read the block from disk