chain_getBlockHash - FLOP RPC Method
Get block hash by number on FLOP. Essential for converting block numbers to hashes, historical queries, and blockchain navigation on the Substrate Proof of Inference Layer 1 built for autonomous AI agents.
FLOP RPC endpoint: endpoint URLs, plans and pricing.
Returns the block hash for a given block number on FLOP. This is the primary method for converting block numbers into block hashes, which are required by most other chain RPC methods.
Why FLOP? Build on the Substrate Proof of Inference Layer 1 built for autonomous AI agents with Proof of Inference with TOPLOC activation commitments, full historical archive state from genesis, and JSON-RPC v2 archive and chainHead APIs.
When to Use This Method
chain_getBlockHash is fundamental for AI agent builders, FLOP miners, indexers, and Substrate developers:
- Historical Queries - Convert block numbers to hashes for state queries at specific heights on FLOP
- Block Navigation - Navigate the blockchain history for Proof of Inference settlement, 1-second BABE blocks with AlephBFT finality, archive state queries, and HTLC atomic swaps
- 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
Best Practices
- Use before
chain_getBlockif you need hash-based block lookup on FLOP - Block numbers may change during chain reorganizations -- hashes are immutable
- Returns
nullfor future blocks that do not exist yet - Cache the genesis block hash as a known reference point
{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [1000000],
"id": 1
}Code Examples
# Get hash for a specific block number
curl -X POST https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [1000000],
"id": 1
}'
# Get hash for the latest block
curl -X POST https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [],
"id": 1
}'Common Use Cases
1. Block Range Iterator
Iterate over a range of blocks on FLOP for indexing:
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 FLOP state at a specific block height:
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 FLOP network:
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 Code | Description | Solution |
|---|---|---|
| -32602 | Invalid params | Block number must be a non-negative integer |
| -32603 | Internal error | Node may be syncing or block not yet available - 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 data by hashchain_getHeader- Get block header by hashchain_getFinalizedHead- Get the latest finalized block hash
chain_getBlock
Retrieve block data by hash on FLOP. Essential for accessing block headers and extrinsics on the Substrate Proof of Inference Layer 1 built for autonomous AI agents.
chain_getFinalizedHead
Get the finalized block hash on FLOP. Essential for confirmed state queries, exchange integrations, and applications requiring irreversible finality on the Substrate Proof of Inference Layer 1 built for autonomous AI agents.