eth_getBlockTransactionCountByHash - GIWA
Example code for the eth_getBlockTransactionCountByHash JSON-RPC method. Complete guide on how to use eth_getBlockTransactionCountByHash JSON-RPC in GetBlock Web3 documentation.
This method returns the number of transactions in a block identified by its hash, as a hex-encoded integer.
Parameters
blockHash
string
Yes
32-byte block hash
Request
curl --location --request POST 'https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x9f2b4c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d"],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getBlockTransactionCountByHash',
params: ['0x9f2b4c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d'],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);import requests
response = requests.post(
'https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_getBlockTransactionCountByHash',
'params': ['0x9f2b4c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d'],
'id': 'getblock.io'
}
)
print(response.json())Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x2a"
}Response Parameters
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
string
Hex-encoded transaction count in the block
Use Cases
Block Sizing: Read how many transactions a block holds before fetching them
Index Iteration: Bound a loop over transaction indices in a block
Throughput Metrics: Sample per-block transaction counts for load analysis
Explorer Backends: Show a transaction count on a block detail page
Error Handling
-32602
Invalid params
Malformed block hash
-32603
Internal error
The node failed to count the block's transactions
Web3 Integration
Last updated
Was this helpful?