Retrieve detailed or basic block information using a block hash. Fetch full block data or key details like transaction hashes, ideal for blockchain analysis or lightweight data retrieval.
The eth_getBlockByHash method is part of the Core API in the Ethereum JSON-RPC retrieves information about a specific block using its block hash.
This method allows users to fetch either the full block data, including detailed transaction details, or just the basic block information with transaction hashes. This flexibility is beneficial for applications that require either comprehensive blockchain analysis or a lighter response focused on key block data.
Supported Networks
The eth_getBlockByHash method supports the following Ethereum networks
Mainnet
Testnet: Sepolia, Holesky
Parameters
DATA, string (32-byte hash): The hash of the block to retrieve (required).
Boolean, true | false:
true: Returns full transaction objects with complete transaction details.
false: Returns only the transaction hashes.
Request
URL
https://go.getblock.io/<ACCESS-TOKEN>/
To make a request to the eth_getBlockByHash method, you can use the following curl command. The request sends a JSON-RPC query to the Ethereum network via the GetBlock API
wscat -c wss://eth.getblock.io/YOUR-API-KEY/ # wait for connection and send the request body {"jsonrpc":"2.0","method":"eth_getBlockByHash","params": ["0xc48fb64230a82f65a08e7280bd8745e7fea87bc7c206309dee32209fe9a985f7",false],"id":"getblock.io"}
Response
The server responds with a JSON object containing the block information. Below is an example response when full transaction objects are requested
id (string): The identifier of the request, as sent by the client. In this case, "getblock.io".
jsonrpc (string): The version of JSON-RPC, here "2.0".
result (object): An object containing information about the block, with the following fields:
difficulty (string): The current difficulty of the block, in hexadecimal format.
extraData (string): Additional data related to the block, in hexadecimal format.
gasLimit (string): The gas limit for the block, in hexadecimal format.
gasUsed (string): The amount of gas used in the block, in hexadecimal format.
hash (string): The hash of the current block, in hexadecimal format.
logsBloom (string): The logs bloom filter for transactions in the block, in hexadecimal format.
miner (string): The address of the miner who mined the block.
mixHash (string): The hash used in the mining process of the block, in hexadecimal format.
nonce (string): A random value used by the miner to find the block hash.
number (string): The block number, in hexadecimal format.
parentHash (string): The hash of the parent block, in hexadecimal format.
receiptsRoot (string): The root hash of all receipts of transactions in the block, in hexadecimal format.
sha3Uncles (string): The hash of the list of all uncle blocks in the block, in hexadecimal format.
size (string): The size of the block in bytes, in hexadecimal format.
stateRoot (string): The root hash of the state after processing the block, in hexadecimal format.
timestamp (string): The timestamp of the block, in hexadecimal format.
totalDifficulty (string): The total difficulty up to and including the current block, in hexadecimal format.
transactions (array of strings): A list of transaction hashes included in the block.
transactionsRoot (string): The root hash of all transactions in the block, in hexadecimal format.
uncles (array of strings): A list of uncle block hashes associated with this block.
Use Case
For developers and blockchain explorers, the eth_getBlockByHash method is crucial for obtaining detailed information about specific blocks in the Ethereum blockchain. This method can be used for:
Verifying transactions within a particular block using the transaction hash.
Retrieving comprehensive block data for in-depth blockchain analysis.
Debugging and investigating specific events on the Ethereum network by examining block data.
Code Example
You can also make requests to the eth_getBlockByHash method programmatically using Python. Below is an example using the requests library
import requestsimport json# Define the API URL and access tokenurl ='https://go.getblock.io/<ACCESS-TOKEN>/'headers ={'Content-Type':'application/json'}# Prepare the request datadata ={"jsonrpc":"2.0","method":"eth_getBlockByHash","params": ["0xb3b20624c0870029c179a9610d55802dc8b651fdfebedb1653d1c06e165faf22",True ],"id":"getblock.io"}# Send the POST requestresponse = requests.post(url, headers=headers, data=json.dumps(data))# Parse the JSON responseresponse_data = response.json()# Print the resultprint(json.dumps(response_data, indent=4))
This Python script sends a request to the eth_getBlockByHash method and prints the returned block information. Make sure to replace with your actual API token. This method provides access to both Ethereum Mainnet and test networks like Sepolia and Goerli, enabling comprehensive blockchain analysis across multiple environments.