eth_getBlockTransactionCountByNumber
https://api.triport.io/v1/ethereumReturns the number of transactions in the block identified by its number or a block tag.
eth_getBlockTransactionCountByNumber returns how many transactions are
contained in a given block, selected by block number (a 0x-prefixed hex
integer) or by one of the named block tags. The count is returned as a
0x-prefixed hexadecimal string.
Use it when you only need the transaction count and not the full block body —
for example to size pagination, to detect empty blocks, or to decide whether a
heavier eth_getBlockByNumber call is worth issuing. If you already have a block
hash instead of a number, use the sibling method
eth_getBlockTransactionCountByHash.
A request for a block that does not exist (e.g. a height beyond the current
chain head) returns a result of null rather than an error.
Parameters
Pass a single-element positional array.
blockParameterstringrequired0x-prefixed hex block number (e.g. 0x149e2c1) or a block tag: latest, earliest, pending, safe, or finalized.Response
"0x9d" decodes to 157 transactions in the block.
jsonrpcstring"2.0".idnumberid.resultstring | null0x-prefixed hex string, or null if the block was not found.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. |
-32602 | invalid_params | The block parameter is missing or not a valid hex number / tag. |
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_getBlockTransactionCountByNumber",
params: ["latest"],
}),
});
const { result } = await res.json();
console.log("tx count:", result === null ? null : parseInt(result, 16)); // 157TypeScript 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_getBlockTransactionCountByNumber",
["0x149e2c1"],
);
console.log("tx count:", result === null ? null : 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_getBlockTransactionCountByNumber",
["latest"],
)
print("tx count:", None if result is None else int(result, 16))Notes
- The result is a hex string — convert with base 16 before arithmetic.
- A non-existent block returns
result: null, not an error; check fornullbefore parsing. eth_getBlockTransactionCountByNumberis 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 look up the count by block hash instead, use
eth_getBlockTransactionCountByHash. To fetch the full block including the transactions themselves, useeth_getBlockByNumber.