eth_getBlockByHash | Polygon

Polygon API method that returns information about the block matching the given block hash. This method can be useful for analyzing a block and its transactions.


Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.


  • hash β€” the hash of the block
  • boolean β€” if true, it returns the detail of each transaction. If false, only the hashes of the transactions.


  • object β€” block object, or null when no block was found.
    • number β€” the block number of the requested block, encoded as hexadecimal. null if the block is pending.
    • hash β€” the block hash of the requested block. null if the block pending.
    • parenthash β€” the hash of the previous block that was used to generate the current block. Also known as the 'parent block'.
    • nonce β€” the hash used to demonstrate proof-of-work. null if the block pending. It returns 0x0000000000000000 when the consensus is proof-of-stake.
    • sha3uncles β€” the hash of the list of uncles included in the block. It is used to identify the block uniquely and to verify the integrity of the block's data.
    • logsbloom β€” the bloom filter for the logs of the block, a data structure that allows for efficient membership testing of elements in a set, in this case, the logs included in the block. null if pending.
    • transactionsroot β€” the root of the transaction trie of the block. The transactionsRoot field allows Ethereum nodes to verify the integrity of the transactions in a block.
    • stateroot β€” the root of the final state trie of the block. The stateroot field is included in the block header and is used to verify the integrity of the state at the time the block was processed
    • receiptsroot β€” the root of the receipts trie of the block. A 32-byte hash of the root node of the receipts trie of all transactions in the block. It is used to verify the integrity of the receipts data for all transactions in the block.
    • miner β€” the address of the miner receiving the reward.
    • difficulty β€” a measure of how hard it is to find a valid block for the Ethereum blockchain. It is a number that increases as more miners join the network and more blocks are added to the chain. Encoded as hexadecimal.
    • totaldifficulty β€” the cumulative sum of the difficulty of all blocks that have been mined in the Ethereum network since the inception of the network. It measures the overall security and integrity of the Ethereum network.
    • extradata β€” the extra data included in a block by the miner who mined it. It often includes messages or other information related to the block.
    • size β€” the size of this block in bytes as an integer value, encoded as hexadecimal.
    • gaslimit β€” the maximum gas allowed in this block, encoded as hexadecimal.
    • gasused β€” the total used gas by all transactions in this block, encoded as hexadecimal.
    • timestamp β€” the Unix timestamp for when the block was collated.
    • transactions β€” array of transaction objects. See eth_getTransactionByHash for the exact shape.
    • uncles β€” the array of uncle hashes.

eth_getBlockByHash code examples

const Web3 = require("web3");
const web3 = new Web3(NODE_URL);

async function getBlock(blockHash) {
    const block = await web3.eth.getBlock(blockHash, false);
const ethers = require('ethers');
const provider = new ethers.JsonRpcProvider(NODE_URL);

const eth_getBlockByHash = async () => {
    const blockByNumber = await provider.send("eth_getBlockByHash", ["0xdfa56bbff2aafaf7b0ac33ca0fd1393ca15830a608763680a563d0a7b4c083ff",false]);

# Polygon is a Proof of Authority (POA) chain. requires the use of the POA compatibility middleware.
from web3 import Web3
from web3.middleware import geth_poa_middleware

web3 = Web3(Web3.HTTPProvider(node_url))

# Inject the POA compatibility middleware to the innermost layer.
web3.middleware_onion.inject(geth_poa_middleware, layer=0)

print(web3.eth.get_block("0x7709b7cacb9a3d647afe557d51891c00ad0c00e01d5bffdbcfe6c1730d36290c", False))

Use case

The eth_getBlockByHash is excellent for analytics purposes. For example, it can be used to quickly find out the hashes of transactions that create new smart contracts. The transactions field, an array of all the transactions within the block, is returned in the response. By iterating through this array and examining each transaction's to field, a user can determine which transactions in the block are creating new smart contracts.

The following example uses the web3.js library to create a function to extract this data:

const Web3 = require("web3");

async function getSmartContractCreations(blockHash) {

  const web3 = new Web3(new Web3.providers.HttpProvider(node_url))

  // Retrieve the block using eth_getBlockByHash
  const block = await web3.eth.getBlock(blockHash, true);
  // Iterate over the transactions in the block
  for (const tx of block.transactions) {
    // Check if the transaction creates a contract (to field = null)
    if ( === null) {
      // This is a contract creation transaction, print the hash of that transaction
      console.log(`This transaction deployed a smart contract: ${tx.hash}`);

const node_url = "CHAINSTACK_NODE_URL" 
// Use the block hash as parameter

The previous example shows how the eth_getBlockByHash method might be used to know which transactions create a smart contract. When a new smart contract is created, the to field will be null. Running this function on a block hash with the transactions detail field set to true will inspect each transaction's to field. If the field is null, the transaction creates a smart contract, printing the transaction hash, which can then be used for further analysis.

Try the eth_getBlockByHash RPC method yourself

Click Try It! to start a request and see the response here!