eth_getBlockTransactionCountByHash
https://api.triport.io/v1/ethereumReturns the number of transactions in the block identified by its block hash.
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 |
|---|---|---|
-32001 | trial_expired | The account's trial period has ended. |
-32003 | 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://api.triport.io/v1/ethereum", {
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));TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const result = await client.ethereum.request<string | null>(
"eth_getBlockTransactionCountByHash",
["0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543"],
);
console.log("tx count:", result === null ? "block not found" : parseInt(result, 16));Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
result = client.ethereum.request(
"eth_getBlockTransactionCountByHash",
["0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543"],
)
print("tx count:", "block not found" if result is None else int(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 tier (
eth_read_rpccategory). - Rate limiting is RPS-per-tier with burst; there is no daily quota. A
-32003 rate_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.