blockchainBlockHeader

Electrum for Bitcoin

Overview

The blockchain.block.header method retrieves the block header at a specified height. Optionally, it can also provide a merkle proof of the header's inclusion in the blockchain up to a specified checkpoint height (cp_height).

Parameters

NameTypeRequiredDescription
heightintegerYesThe height of the block.
cp_heightintegerNoCheckpoint height for the merkle proof, defaults to 0 (disabled).

Returns

Depending on the value of cp_height, the method returns either the raw block header as a hexadecimal string or a dictionary providing a merkle proof:

FieldDescription
branchAn array of hashes in the merkle branch leading up to the checkpoint root.
headerThe raw block header as a hexadecimal string.
rootThe merkle root of all blockchain headers up to and including cp_height.

Example Result

If cp_height is 0:

{
  "header": "00000020a....61723"
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/bitcoin-mainnet-electrs/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "method": "blockchain.block.header",
    "params": [5, 0],
    "id": 1,
    "jsonrpc": "2.0"
}'
// yarn add @tatumio/tatum

import { TatumSDK, BitcoinElectrs, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<BitcoinElectrs>({ network: Network.BITCOIN_ELECTRS })

const headerInfo = await tatum.rpc.getBlockHeader({
  height: 5,
  cp_height: 0,
})

console.log(headerInfo)

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs