eth_getBlockByHash
Returns information about a block by hash on Optimism.
Why Optimism? Build on the heart of the Superchain powering 60%+ of Ethereum L2 transactions with $6B+ TVL with OP Stack modularity, Superchain interoperability, 17M+ daily transactions across 33 chains, and 20% of tokens for public goods.
Use Cases#
The eth_getBlockByHash method is essential for:
- Block verification - Verify block data using its unique hash
- Chain reorganization handling - Track blocks during reorgs
- Cross-chain bridges - Verify block finality for cross-chain DeFi, Superchain-interoperable dApps, and public goods funding recipients
- Deterministic queries - Get consistent block data regardless of chain state
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockHash | DATA | Yes | 32-byte block hash |
fullTransactions | Boolean | Yes | If true, returns full transaction objects; if false, returns transaction hashes |
Request#
{
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x76cde4f6f885fe27962356115e0ff0539058a03e8b9e15dac3fb40a9caa0bc47",
false
],
"id": 1
}
Returns#
Returns the same block object as eth_getBlockByNumber, or null if no block is found.
| Field | Type | Description |
|---|---|---|
number | QUANTITY | Block number |
hash | DATA | 32-byte block hash |
parentHash | DATA | 32-byte parent block hash |
timestamp | QUANTITY | Unix timestamp |
gasUsed | QUANTITY | Total gas used |
transactions | Array | Transaction objects or hashes |
Code Examples#
- cURL
- JavaScript
- Python
- Go
curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x76cde4f6f885fe27962356115e0ff0539058a03e8b9e15dac3fb40a9caa0bc47",
false
],
"id": 1
}'
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
const blockHash = '0x76cde4f6f885fe27962356115e0ff0539058a03e8b9e15dac3fb40a9caa0bc47';
const block = await provider.getBlock(blockHash);
console.log('Block number:', block.number);
console.log('Timestamp:', new Date(block.timestamp * 1000));
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY'))
block_hash = '0x76cde4f6f885fe27962356115e0ff0539058a03e8b9e15dac3fb40a9caa0bc47'
block = w3.eth.get_block(block_hash)
print(f'Block number: {block.number}')
print(f'Timestamp: {block.timestamp}')
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY")
if err != nil {
log.Fatal(err)
}
blockHash := common.HexToHash("0x76cde4f6f885fe27962356115e0ff0539058a03e8b9e15dac3fb40a9caa0bc47")
block, err := client.BlockByHash(context.Background(), blockHash)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Block number: %d\n", block.Number().Uint64())
}
Error Handling#
| Error Code | Message | Description |
|---|---|---|
| -32602 | Invalid params | Invalid block hash format |
| -32000 | Block not found | Block with this hash does not exist |
Related Methods#
eth_getBlockByNumber- Get block by numbereth_blockNumber- Get latest block number