eth_getBlockByHash | Ethereum
Ethereum 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.
Parameters
hash
— the hash of the blockboolean
— iftrue
, it returns the detail of each transaction. Iffalse
, only the hashes of the transactions.
Response
object
— block object, ornull
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 returns0x0000000000000000
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. ThetransactionsRoot
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. Thestateroot
field is included in the block header and is used to verify the integrity of the state at the time the block was processedreceiptsroot
— 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
—null
. This field is obsolete as it was used during Ethereum’s Proof of Work (PoW) era to track cumulative mining difficulty. After the merge to Proof of Stake (PoS), this value is no longer relevant.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
Learn more about the ChainstackProvider
in ethers.js
: ethers ChainstackProvider Documentation.
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:
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.
Body
1
"2.0"
"eth_getBlockByHash"
The hash identifying the block.