TriportRPC

eth_getBlockTransactionCountByNumber

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

Returns the number of transactions in a Polygon block identified by its number or a block tag.

Polygonpolygon_read_rpcfree 15 RPS · basic 20 RPS · pro 100 RPS · business 250 RPS

eth_getBlockTransactionCountByNumber returns how many transactions are contained in a given Polygon 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.

This is a light read on the free tier (polygon_read_rpc category). Polygon blocks are produced about every ~2.1 seconds and typically carry ~50–150 transactions, so latest advances quickly — poll on roughly that cadence if you are tracking the chain tip. 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.

blockParameterstringrequired
Either a 0x-prefixed hex block number (e.g. 0x3a2b1f0) or a block tag: latest, earliest, pending, safe, or finalized.

Response

"0x5e" decodes to 94 transactions in the block.

jsonrpcstring
JSON-RPC version, always "2.0".
idnumber
Echoes the request id.
resultstring | null
Number of transactions in the block as a 0x-prefixed hex string, or null if the block was not found.

Errors

CodeMeaningWhen it happens
-32001trial_expiredThe account's trial period has ended.
-32002tier_insufficientThe API key's tier is below the level required for this method.
-32003rate_limitedThe per-tier RPS limit was exceeded. Back off and retry.
-32004subscription_expiredThe account's subscription has lapsed.
-32005unauthorizedMissing or invalid API key.
-32601method_unknownThe method name is not recognized or not enabled for this network.

See errors.md for the full error envelope and handling guidance.

Examples

JavaScript (fetch)

const res = await fetch("https://api.triport.io/v1/polygon", {
  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)); // 94

TypeScript SDK (@triport/sdk)

import { Triport } from "@triport/sdk";


const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });


const result = await client.polygon.request<string | null>(
  "eth_getBlockTransactionCountByNumber",
  ["0x3a2b1f0"],
);
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.polygon.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 for null before parsing.
  • Polygon blocks are produced roughly every 2.1 seconds; a latest count goes stale almost immediately, so re-request rather than caching it.
  • 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 look up the count by block hash instead, use eth_getBlockTransactionCountByHash. To fetch the full block including the transactions themselves, use eth_getBlockByNumber.