The eth_getBlockTransactionCountByHash
method returns the number of transactions in a block, identified by the block's hash. This lightweight method provides a quick way to check transaction volume without retrieving the full block data, making it useful for block explorers and network analysis tools.
This method accepts a block hash and returns the number of transactions in that block, providing a simple yet efficient way to gauge block activity.
The hash (32 bytes) of the block
The number of transactions in the specified block (hexadecimal)
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x134" // 308 transactions in decimal
}
The response is a hexadecimal string representing the number of transactions in the block:
"0x0"
means the block has no transactions (empty block)"0x1"
means there is only one transaction"0x134"
(as shown above) converts to 308 in decimal, indicating 308 transactionsTo convert the hex response to decimal in JavaScript:
const txCount = parseInt("0x134", 16); // 308
This method uses a block hash as an identifier, which has these characteristics:
If you have a block number instead of a hash, use eth_getBlockTransactionCountByNumber
instead.
// Example: Find blocks with high transaction counts
const significantBlockHashes = [
'0xba9ded5ca1ec9adb9451bf053b33cbf5bd60f2a7ea39256278db165de9a88e5c', // Example high-activity block
'0xb37a9f99b47975acc1ea43bd2e02e0567566bd3dad8f034ab676b4a94d1bac9a', // Another block to check
'0x98c3125c2993d90b396f638115821ba17b9852e4001869061b800d32f96cdd2b', // Yet another block
];
async function findHighActivityBlocks(blockHashes, threshold = 100) {
const results = [];
for (const hash of blockHashes) {
const count = await provider.send('eth_getBlockTransactionCountByHash', [hash]);
const txCount = parseInt(count, 16);
if (txCount > threshold) {
results.push({
blockHash: hash,
transactionCount: txCount,
});
}
}
return results.sort((a, b) => b.transactionCount - a.transactionCount);
}
// Usage
const highActivityBlocks = await findHighActivityBlocks(significantBlockHashes);
console.log('Blocks with high transaction counts:', highActivityBlocks);
Transaction counts per block have evolved significantly throughout Ethereum's history:
High transaction counts typically correlate with: