Skip to main content

chain_getBlockHash - JSON-RPC Method

Description#

Retrieves the unique 32-byte block hash for a specified block number on the Acala blockchain. Block hashes serve as immutable identifiers for blocks and are used throughout the Substrate framework to reference specific blocks when querying historical data or verifying chain state. Each block hash is derived cryptographically from the block header contents, ensuring uniqueness and integrity. When called without parameters, this method returns the hash of the most recent block known to the node.

Request Examples#

# Get hash of latest block
curl -s https://api-acala.n.dwellir.com/YOUR_API_KEY \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"chain_getBlockHash","params":[]}'

# Get hash for specific block number 100000
curl -s https://api-acala.n.dwellir.com/YOUR_API_KEY \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"chain_getBlockHash","params":[100000]}'

Parameters#

ParameterTypeRequiredDescription
block_numbernumberNoBlock number (height). Omit to get latest block hash

Response Format#

Returns a 32-byte hash in hexadecimal format prefixed with 0x. This hash uniquely identifies the block and can be used with other RPC methods that require block identification, such as chain_getBlock or state queries at specific block heights.

Use Cases#

  • Historical Queries: Obtain block hashes for querying state or data at specific historical points
  • Block Navigation: Convert block numbers to hashes for API methods requiring hash-based block identification
  • Chain Verification: Verify blockchain continuity by checking parent hash relationships between consecutive blocks
  • Bookmarking: Store block hashes as checkpoints for resuming blockchain data processing after interruptions
  • Event Indexing: Map event occurrences to specific block hashes for precise historical referencing

Block Number vs Block Hash#

While block numbers provide sequential ordering, block hashes offer cryptographic guarantees of block content integrity. In scenarios involving chain reorganizations (though rare on finalized blocks), block numbers might temporarily reference different blocks, while block hashes always reference exact, immutable block content. For critical applications requiring certainty, always use finalized block hashes.

Best Practices#

Cache block hashes for frequently accessed historical blocks to minimize API calls. When processing sequential blocks, retrieve hashes in batches rather than individual requests where possible. Always verify that blocks are finalized before treating their hashes as permanent references, as non-finalized blocks may be subject to reorganization.

Performance Notes#

This is a lightweight query that executes quickly even for historical blocks. Archive nodes can serve hashes for any block in history, while pruned nodes may only have access to recent blocks within their pruning window.