⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_getBlockByHash

Returns information about a block by block hash.

When to Use This Method

Use eth_getBlockByHash to:

  • Retrieve Specific Block - Get block data using its unique hash
  • Verify Block Integrity - Confirm block contents haven't changed
  • Cross-Reference Blocks - Link transactions to specific blocks
  • Chain Reorganization Detection - Track block validity
  • Historical Data Access - Query immutable block records

Parameters

  1. Block Hash (required):

    • 32-byte block hash as hexadecimal
  2. Transaction Details (required):

    • true - Returns full transaction objects
    • false - Returns only transaction hashes
{
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
true
],
"id": 1
}

Returns

Block object or null if block not found.

Implementation Examples

curl -X POST https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
true
],
"id": 1
}'

Common Use Cases

Block Verification

async function verifyBlock(blockHash, expectedData) {
const block = await provider.getBlock(blockHash, true);

if (!block) {
throw new Error('Block not found');
}

return {
valid: true,
number: block.number,
transactionCount: block.transactions.length,
timestamp: new Date(block.timestamp * 1000),
gasUsed: block.gasUsed
};
}

Best Practices

  1. Always check for null responses
  2. Cache block data when possible
  3. Use block hashes for permanent references
  4. Validate block hash format before querying

Error Codes

CodeMessageDescription
-32602Invalid paramsInvalid block hash format
-32000Block not foundBlock doesn't exist