TriportRPC

eth_getBlockTransactionCountByHash

POSThttps://api.triport.io/v1/ethereum

Returns the number of transactions in the block identified by its block hash.

Ethereumeth_read_rpcfree 10 RPS · basic 20 RPS · pro 100 RPS · business 250 RPS

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.

blockHashstringrequired
32-byte block hash, 0x-prefixed (66 characters total).

Response

When the block hash is unknown, the result is null:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": null
}
jsonrpcstring
JSON-RPC version, always "2.0".
idnumber
Echoes the request id.
resultstring | null
Transaction count as a 0x-prefixed hex integer (e.g. 0x9b = 155), or null if no block matches the hash.

Errors

CodeMeaningWhen it happens
-32001trial_expiredThe account's trial period has ended.
-32003rate_limitedThe 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 null case: an unknown or non-canonical block hash returns result: null rather than an error.
  • Available on the free tier (eth_read_rpc category).
  • Rate limiting is RPS-per-tier with burst; there is no daily quota. A -32003 rate_limited error 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, use eth_getTransactionByBlockHashAndIndex.