⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip the expensive compute units.
Switch Today →
Skip to main content

chain_getHeader - JSON-RPC Method

Description

Retrieves the header of a specific block without the body (extrinsics). This JSON-RPC method is more efficient than chain_getBlock when you only need header information like parent hash, block number, and state root.

Parameters

ParameterTypeRequiredDescription
blockHashstringNoHex-encoded block hash. If omitted, returns the latest block header

Returns

FieldTypeDescription
parentHashstringHash of the parent block
numberstringBlock number (hex-encoded)
stateRootstringRoot of the state trie after executing this block
extrinsicsRootstringRoot of the extrinsics trie
digestobjectDigest items (consensus messages, seal, etc.)

Request Example

{
"jsonrpc": "2.0",
"method": "chain_getHeader",
"params": [],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"result": {
"parentHash": "0x4a84d1c5fc5c725b26a3c8e126d8f65e1c2d2dc5b3fcbc91e67e7637fa136789",
"number": "0x123456",
"stateRoot": "0x8f7a82e2e0f3e73f5e232e68de18144f6e7a52a6db39bb5e5e3d9ca6e1f72845",
"extrinsicsRoot": "0x2e6f9a7d2c4b3e1a8f5c6d9e4b1a7c3f8e5d2a9b6c4e1f8a5d3c2b9e7f6a4d38",
"digest": {
"logs": [
"0x0642414245b501013c0000009d2ef70f00000000",
"0x054241424501019e7b3c4e1f8a2d5c6b9e4f3a7d2c5e8b1f4a6d9c3e2b5f8a7c4d"
]
}
},
"id": 1
}

Code Examples

JavaScript

const getHeader = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];

const response = await fetch('https://api-polkadot.n.dwellir.com', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'chain_getHeader',
params: params,
id: 1
})
});

const data = await response.json();
return data.result;
};

// Get latest header
const header = await getHeader();
console.log('Latest block:', parseInt(header.number, 16));

Python

import requests
import json

def get_header(block_hash=None):
url = "https://api-polkadot.n.dwellir.com"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}

params = [block_hash] if block_hash else []

payload = {
"jsonrpc": "2.0",
"method": "chain_getHeader",
"params": params,
"id": 1
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
return response.json()["result"]

# Get header info
header = get_header()
block_number = int(header["number"], 16)
print(f"Block #{block_number}")
print(f"Parent: {header['parentHash']}")
print(f"State Root: {header['stateRoot']}")

Use Cases

  1. Light Clients: Verify chain without downloading full blocks
  2. Block Monitoring: Track new blocks with minimal data transfer
  3. Fork Detection: Compare parent hashes to detect chain reorganizations
  4. State Verification: Validate state roots for merkle proofs