chain_getHeader - Hydration RPC Method
Get block header on Hydration. Lightweight alternative to chain_getBlock for reading block metadata, parent hash, and state root on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin.
Returns the block header for a given hash on Hydration. This is a lightweight alternative to chain_getBlock when you only need header metadata without extrinsic data.
Why Hydration? Build on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin with Omnipool with reduced slippage, permissioned listings, 3M DOT DAO allocation, and 200%+ APR farm yields.
When to Use This Method
chain_getHeader is ideal for DeFi developers, liquidity providers, and DAOs requiring capital-efficient trading:
- Lightweight Queries — Get block metadata without downloading full extrinsic data on Hydration
- Chain Synchronization — Track block production and monitor chain progress for single-sided liquidity provision, cross-chain trading (SOL, KSM, tBTC), and HOLLAR decentralized stablecoin
- Parent Chain Navigation — Follow
parentHashlinks to traverse the chain backwards - State Verification — Use
stateRootandextrinsicsRootfor Merkle proof verification
Code Examples
Common Use Cases
1. Block Time Calculator
Estimate block production rate on Hydration:
async function estimateBlockTime(api, sampleSize = 10) {
const latestHeader = await api.rpc.chain.getHeader();
const latestNumber = latestHeader.number.toNumber();
const oldHash = await api.rpc.chain.getBlockHash(latestNumber - sampleSize);
const oldHeader = await api.rpc.chain.getHeader(oldHash);
// Use timestamp from block digests or timestamp pallet
const latestTimestamp = await api.query.timestamp.now();
const apiAt = await api.at(oldHash);
const oldTimestamp = await apiAt.query.timestamp.now();
const timeDiff = latestTimestamp.toNumber() - oldTimestamp.toNumber();
const avgBlockTime = timeDiff / sampleSize;
console.log(`Average block time: ${avgBlockTime / 1000}s over ${sampleSize} blocks`);
return avgBlockTime;
}2. Chain Traversal
Walk backwards through the Hydration chain using parent hashes:
async function walkChain(api, startHash, depth = 5) {
let currentHash = startHash || (await api.rpc.chain.getBlockHash());
const headers = [];
for (let i = 0; i < depth; i++) {
const header = await api.rpc.chain.getHeader(currentHash);
headers.push({
number: header.number.toNumber(),
hash: currentHash.toString(),
parentHash: header.parentHash.toHex()
});
currentHash = header.parentHash;
}
return headers;
}3. Lightweight Block Monitor
Monitor Hydration block production without downloading full blocks:
async function monitorBlocks(api, callback) {
let lastNumber = 0;
setInterval(async () => {
const header = await api.rpc.chain.getHeader();
const number = header.number.toNumber();
if (number > lastNumber) {
console.log(`New block #${number}`);
callback(header);
lastNumber = number;
}
}, 3000);
}Error Handling
| Error Code | Description | Solution |
|---|---|---|
| -32602 | Invalid params | Verify block hash is valid hex with 0x prefix |
| -32603 | Internal error | Node may be syncing — retry with backoff |
| -32601 | Method not found | Verify the node supports this RPC method |
| -32005 | Rate limit exceeded | Implement client-side rate limiting |
Related Methods
chain_getBlock— Get full block with extrinsicschain_getBlockHash— Get block hash by numberchain_subscribeNewHeads— Subscribe to new block headers in real timechain_subscribeFinalizedHeads— Subscribe to finalized block headers
chain_getFinalizedHead
Get the finalized block hash on Hydration. Essential for confirmed state queries, exchange integrations, and applications requiring irreversible finality on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin.
chain_subscribeNewHeads
Subscribe to new block headers on Hydration. Real-time WebSocket notifications for every new block as it is produced — essential for monitoring, indexing, and event-driven applications on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin.