eth_getBlockTransactionCountByHash - Base
Example code for the eth_getBlockTransactionCountByHash JSON-RPC method. Complete guide on how to use eth_getBlockTransactionCountByHash JSON-RPC in GetBlock Web3 documentation.
The eth_getBlockTransactionCountByHash method returns the number of transactions in a block matching the given block hash. This is useful for quickly determining block activity without fetching full block data.
Parameters
blockHash
string
Yes
32-byte hash of the block
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2"],
"id": "getblock.io"
}'const axios = require('axios');
const blockHash = '0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2';
const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getBlockTransactionCountByHash',
params: [blockHash],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const txCount = parseInt(response.data.result, 16);
console.log('Transaction Count:', txCount);Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x8"
}Response Parameters
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
string
Number of transactions in the block (hex)
Use Cases
Block Analysis: Quickly assess block activity levels
Network Monitoring: Track transaction throughput
Data Validation: Verify block data integrity
Indexing Optimization: Plan batch processing based on tx count
Statistics Collection: Gather block-level metrics
Error Handling
-32602
Invalid params
Invalid block hash format
-32603
Internal error
Block not found
Web3 Integration
Last updated
Was this helpful?