eth_getBlockTransactionCountByHash — Ethereum JSON-RPC
Returns the number of transactions in the block identified by its block hash.
https://triport.io/eth- Network
- Ethereum
- Scope
- eth_read_rpc
- Auth
- x-token: $TRIPORT_API_KEY (or Authorization: Bearer)
- Rate limit
- free 10 RPS sustained · up to 20 burst · basic 20 RPS sustained · up to 40 burst · pro 100 RPS sustained · up to 200 burst · business 250 RPS sustained · up to 500 burst; Burst capacity
Endpoint and plans: Ethereum RPC endpoint.
eth_getBlockTransactionCountByHash looks up a block by its 32-byte hash and
returns how many transactions that block contains, encoded as a 0x-prefixed
hexadecimal string.
Use it when you already hold a block hash — for example from a log, a receipt,
or an eth_getBlockByHash response — and you only need the transaction count
rather than the full block body. Pairing the count with
eth_getTransactionByBlockHashAndIndex lets you page through a block's
transactions by index without downloading the entire block.
If no block matches the supplied hash (e.g. it belongs to an orphaned/uncle
block, or the node has not yet seen it), the method returns null instead of an
error. Always check for null before parsing the result as a number.
Parameters
The method takes a single positional parameter.
blockHashstringrequired0x-prefixed (66 characters total).Response
When the block hash is unknown, the result is null:
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}jsonrpcstring"2.0".idnumberid.resultstring | null0x-prefixed hex integer (e.g. 0x9b = 155), or null if no block matches the hash.Errors
| Code | Meaning | When it happens |
|---|---|---|
401 | trial_expired | The account's trial period has ended. |
429 | rate_limited | The per-tier RPS limit was exceeded. Back off and retry. |
A missing block is not an error — it is reported as result: null (see
above). See errors.md for the full error envelope and
handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://triport.io/eth", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_getBlockTransactionCountByHash",
params: ["0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543"],
}),
});
const { result } = await res.json();
console.log("tx count:", result === null ? "block not found" : parseInt(result, 16));Notes
- The result is a hex string (or
null), not a number — convert with base 16 before arithmetic. - Always handle the
nullcase: an unknown or non-canonical block hash returnsresult: nullrather than an error. - Available on the Free trial (
eth_read_rpccategory). - Rate limiting is RPS-per-tier with burst; there is no daily quota. An
HTTP
429rate_limitederror means you should back off and retry shortly. - To count transactions by block height instead of hash, use
eth_getBlockTransactionCountByNumber. To fetch an individual transaction from the block, useeth_getTransactionByBlockHashAndIndex.