Docs

chain_getBlockHash - Bifrost RPC Method

Get block hash by number on Bifrost. Essential for converting block numbers to hashes, historical queries, and blockchain navigation on Polkadot's largest liquid staking appchain with 60% DOT LST market share and $125M+ TVL.

Returns the block hash for a given block number on Bifrost. This is the primary method for converting block numbers into block hashes, which are required by most other chain RPC methods.

Why Bifrost? Build on Polkadot's largest liquid staking appchain with 60% DOT LST market share and $125M+ TVL with first LST governance on OpenGov, 60% DOT market share, Hyperbridge ETH integration, and 500K DOT treasury support.

When to Use This Method

chain_getBlockHash is fundamental for liquid staking developers, DeFi builders, and teams requiring cross-chain yield solutions:

  • Historical Queries — Convert block numbers to hashes for state queries at specific heights on Bifrost
  • Block Navigation — Navigate the blockchain history for omnichain liquid staking (vDOT, vKSM, vGLMR, vMOVR, vASTR), cross-chain vToken governance, and DOT/ETH liquidity bridging
  • Data Indexing — Build block number-to-hash mappings for indexers and explorers
  • Cross-Reference — Translate block numbers from events or logs into hashes for detailed lookups

Code Examples

Common Use Cases

1. Block Range Iterator

Iterate over a range of blocks on Bifrost for indexing:

JavaScript
async function iterateBlocks(api, startBlock, endBlock) {
  for (let num = startBlock; num <= endBlock; num++) {
    const hash = await api.rpc.chain.getBlockHash(num);
    const block = await api.rpc.chain.getBlock(hash);

    console.log(`Block #${num}: ${block.block.extrinsics.length} extrinsics`);
  }
}

2. Historical State Query

Query Bifrost state at a specific block height:

JavaScript
async function getBalanceAtBlock(api, address, blockNumber) {
  const blockHash = await api.rpc.chain.getBlockHash(blockNumber);
  const apiAt = await api.at(blockHash);
  const account = await apiAt.query.system.account(address);

  return {
    blockNumber,
    free: account.data.free.toString(),
    reserved: account.data.reserved.toString()
  };
}

3. Genesis Hash Verification

Verify you are connected to the correct Bifrost network:

JavaScript
async function verifyNetwork(api, expectedGenesisHash) {
  const genesisHash = await api.rpc.chain.getBlockHash(0);

  if (genesisHash.toHex() !== expectedGenesisHash) {
    throw new Error(`Wrong network! Expected ${expectedGenesisHash}, got ${genesisHash.toHex()}`);
  }

  console.log('Connected to correct network');
}

Error Handling

Error CodeDescriptionSolution
-32602Invalid paramsBlock number must be a non-negative integer
-32603Internal errorNode may be syncing or block not yet available — retry with backoff
-32601Method not foundVerify the node supports this RPC method
-32005Rate limit exceededImplement client-side rate limiting