chain_getHeader
Description#
Returns the header for a given block hash. When params are omitted, it returns the header for the most recent block known to the node (best or finalized, depending on implementation). Use this to track block numbers, parent hashes, and state/extrinsics roots.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockHash | string | No | Hex-encoded block hash. If omitted, the latest block header is returned |
Returns#
| Field | Type | Description |
|---|---|---|
parentHash | string | Hash of the parent block |
number | string | Block number encoded as hex |
stateRoot | string | State trie merkle root |
extrinsicsRoot | string | Extrinsics merkle root |
digest | object | Digest logs ( |
preRuntime, consensus, seal, etc.) |
Request Example#
{
"jsonrpc": "2.0",
"method": "chain_getHeader",
"params": [
"0xd4b3a0e3b88b7c25215926bbf7c733f5c31e69c0c8c4b4a86d6ec3f3f086e95d"
],
"id": 1
}
Response Example#
{
"jsonrpc": "2.0",
"result": {
"parentHash": "0x65b246e9b69a61f842104a15307ae906013c56a8bb6c942555b1a71424b4bab3",
"number": "0x9055f2",
"stateRoot": "0x220ea5bd35df99176268d8cbcee287a8a81a2e8addfa764661f71af591db0329",
"extrinsicsRoot": "0x388e5e2bb951b1dfac3f6a3f0c1d5de1ace6e413008efe48f1a54228dcd049db",
"digest": {
"logs": [
"0x0661757261208a2c7a1100000000",
"0x0452505352903006d1651014effe612aeb9e2bed207fca849e69a1d4594bdab580afc68677458a62ad06"
]
}
},
"id": 1
}
Headers are captured from block #9,053,714 on 2025-10-03 07:42:18 UTC.
Code Examples#
- cURL
- JavaScript
curl https://api-bifrost-polkadot.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getHeader",
"params": [],
"id": 1
}'
const response = await fetch('https://api-bifrost-polkadot.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'chain_getHeader',
params: ['0xd4b3a0e3b88b7c25215926bbf7c733f5c31e69c0c8c4b4a86d6ec3f3f086e95d'],
id: 1
})
});
const { result } = await response.json();
console.log(parseInt(result.number, 16));
Rust (subxt)#
use subxt::{config::substrate::SubstrateConfig, OnlineClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = OnlineClient::<SubstrateConfig>::from_url(
"wss://api-bifrost-polkadot.n.dwellir.com/YOUR_API_KEY"
).await?;
let hash = "0xd4b3a0e3b88b7c25215926bbf7c733f5c31e69c0c8c4b4a86d6ec3f3f086e95d".parse()?;
let header = api.rpc().header(Some(hash)).await?.expect("header");
println!("Block #{}", header.number);
println!("State root {}", header.state_root);
Ok(())
}
Usage Notes#
- When replaying blocks, pair
chain_getHeaderwithchain_getBlockto fetch extrinsics and events. - Use
chain_getHeader+chain_getFinalizedHeadto confirm finality before crediting cross-chain transfers.