eth_getBlockTransactionCountByNumber | Ethereum
Ethereum API method that returns the number of transactions in a block specified by block number or tag. This information can be useful for analytics purposes.
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
-
quantity or tag
— the integer of a block encoded as hexadecimal or the string with:latest
— the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.safe
— the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.finalized
— the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked ETH to be burned.earliest
— the earliest available or genesis blockpending
— the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.
Response
quantity
— an integer value representing how many transactions are included in the block.
eth_getBlockTransactionCountByNumber
code examples
Learn more about the ChainstackProvider
in ethers.js
: ethers ChainstackProvider Documentation.
Use case
eth_getBlockTransactionCountByNumber
can be used to analyze how many transactions are included on the Ethereum blockchain in a certain period. For instance, a new block is generated on the Ethereum blockchain every 12 seconds, resulting in approximately 300 blocks per hour. Using the ethers.js library, one can inspect the past 300 blocks starting from the latest block and use eth_getBlockTransactionCountByNumber
to find the number of transactions in each block to sum them.
Using eth_getBlockTransactionCountByNumber
is a bit more straightforward compared to the example shown using eth_getBlockTransactionCountByHash
for this same use case, you don’t need to extract the block hash. Instead, you can query the transaction count directly.
This example is made using the ethers.js library, and you can notice that it requires more parsing compared to web3.js, and the results are given as hexadecimal.
Body
The block number or tag.