rest/headers - Bitcoin

This endpoint returns a run of block headers, starting at the given block and walking forward along the main chain. Headers carry no transactions, which makes this the cheapest way to follow the chain.

Parameters

ParameterTypeLocationRequiredDescription
countintegerpathYesMaximum number of headers to return, starting at the given block
hashstringpathYesHash of the first block in the run
formatstringpathYesResponse format appended to the hash: json, hex, or bin

Request

bashcurl --location --request GET 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/headers/3/0000000000000000000159d94328a0362aba4418de918cba6830e550f8e50bd8.json'

example.js

javascriptconst response = await fetch(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/headers/3/0000000000000000000159d94328a0362aba4418de918cba6830e550f8e50bd8.json'
);
console.log(await response.json());

example.py

pythonimport requests

response = requests.get('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/headers/3/0000000000000000000159d94328a0362aba4418de918cba6830e550f8e50bd8.json')

print(response.json())

Response

json[
    {
        "hash": "0000000000000000000159d94328a0362aba4418de918cba6830e550f8e50bd8",
        "confirmations": 2,
        "height": 967815,
        "version": 673554432,
        "versionHex": "2825a000",
        "merkleroot": "4612f8a6b32041ac0b96734a0d04cbeaa887626e7b86b16bf4aa21c4b13bf8e2",
        "time": 1789897746,
        "mediantime": 1789892647,
        "nonce": 1600482865,
        "bits": "17021ec5",
        "target": "000000000000000000021ec50000000000000000000000000000000000000000",
        "difficulty": 132757073449487.5,
        "chainwork": "000000000000000000000000000000000000000148e3a9f92772ad6bab940cd0",
        "nTx": 4162,
        "previousblockhash": "0000000000000000000111b4d4c4fd8b3913403adf3ae8a3ae0932452918fd4e",
        "nextblockhash": "000000000000000000019c481c042c0625abe1dc04fe26795e2e24b152791e5f"
    },
    {
        "hash": "000000000000000000019c481c042c0625abe1dc04fe26795e2e24b152791e5f",
        "confirmations": 1,
        "height": 967816,
        "version": 617037824,
        "versionHex": "24c74000",
        "merkleroot": "7b7ffdc51c5adbc40f8c209747b7c82f083f647e555cd0ef80b8acf66df21ebf",
        "time": 1789899076,
        "mediantime": 1789892696,
        "nonce": 1539191330,
        "bits": "17021ec5",
        "target": "000000000000000000021ec50000000000000000000000000000000000000000",
        "difficulty": 132757073449487.5,
        "chainwork": "000000000000000000000000000000000000000148e422b78a65626de4ddb156",
        "nTx": 4131,
        "previousblockhash": "0000000000000000000159d94328a0362aba4418de918cba6830e550f8e50bd8"
    }
]

Response Parameters

FieldTypeDescription
hashstringThe block hash
confirmationsnumericDepth of the block
heightnumericBlock height
versionnumericBlock version
merklerootstringMerkle root of the block's transactions
timenumericBlock time as a Unix timestamp
mediantimenumericMedian time of the preceding 11 blocks
noncenumericProof-of-work nonce
bitsstringCompact difficulty target
difficultynumericDifficulty as a multiple of the minimum
chainworkstringCumulative work up to this block
nTxnumericNumber of transactions in the block
previousblockhashstringHash of the preceding block

count is a maximum, not a guarantee. The run stops at the chain tip: the request above asks for three headers from height 967,815 and returns two, because the tip was 967,816.

The run walks forward from the block given, so pass the oldest block you want, not the newest.

Use Cases

  • Light Sync: Follow the chain by headers without downloading blocks
  • Reorg Detection: Compare a stored header run against the node's current view
  • Timestamp Series: Build a height-to-time mapping cheaply

Error Handling

HTTP StatusMessageDescription
400Bad requestThe path is malformed, or a hash or height is invalid
403ForbiddenMissing or invalid ACCESS-TOKEN
404Not foundNo object matches the requested hash, height, or outpoint
500Internal errorThe node failed to process the request