eth_getTransactionByBlockNumberAndIndex
https://api.triport.io/polygonReturns a single Polygon transaction selected by its block (number or tag) and its zero-based position within that block.
eth_getTransactionByBlockNumberAndIndex returns one transaction identified by
two coordinates: the block (given as a hex-encoded block number or one of the
tags latest, earliest, pending, safe, finalized) and the transaction's
zero-based index within that block. Both parameters are passed as 0x-prefixed
hex strings.
Reach for it when you already know a transaction's slot in a block — for example
while iterating a Polygon block transaction-by-transaction, or when you have an
index from a prior eth_getBlockByNumber call and
want only that one body rather than the whole block. This is the by-number
counterpart of eth_getTransactionByBlockHashAndIndex; use that sibling when you
hold the block hash instead, or eth_getTransactionByHash
when you already have the transaction's own hash.
Polygon runs Bor consensus with a ~2.1 s block time, so a typical block carries
roughly 50–150 transactions. If the block does not exist, or the index is out of
range for that block, result is null rather than an error — check for null
before reading fields.
Parameters
Positional params array: [blockNumber, transactionIndex].
blockNumberstringrequired"0x3b9aca00") or a tag: latest, earliest, pending, safe, or finalized.transactionIndexstringrequired0x-prefixed hex integer (e.g. "0x0" for the first transaction).Response
Response fields
| Field | Type | Description |
|---|---|---|
jsonrpc | string | JSON-RPC version, always "2.0". |
id | number | Echoes the request id. |
result | object | null | The transaction object, or null if the block was not found or the index is out of range. |
The transaction object carries the standard EVM fields:
| Field | Type | Description |
|---|---|---|
blockHash | string | Hash of the containing block; null if pending. |
blockNumber | string (hex) | Block number; null if pending. |
from | string | Sender address. |
to | string | null | Recipient address; null for contract-creation transactions. |
gas | string (hex) | Gas supplied by the sender. |
gasPrice | string (hex) | Effective gas price, in wei. |
maxFeePerGas | string (hex) | Max fee per gas — present on EIP-1559 (type 0x2) transactions. |
maxPriorityFeePerGas | string (hex) | Max priority fee per gas — present on EIP-1559 transactions. |
hash | string | Transaction hash. |
input | string | Call data, hex. |
nonce | string (hex) | Sender nonce. |
transactionIndex | string (hex) | Index of the transaction in the block. |
value | string (hex) | Value transferred, in wei. |
type | string | Transaction type (0x0 legacy, 0x1 access-list, 0x2 EIP-1559). |
chainId | string (hex) | Chain ID — 0x89 (137) for Polygon mainnet. |
v, r, s | string (hex) | ECDSA signature components. |
Errors
Errors arrive in the standard JSON-RPC error object; the extra fields move
into error.data.
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The free 7-day trial has ended. |
-32002 | tier_insufficient | Your tier is below what the method requires. (Not expected here — this method is free-tier.) |
-32003 | rate_limited | You exceeded the sustained rps for your tier; respect Retry-After / data.retry_after_sec. |
-32004 | subscription_expired | A previously active paid subscription has lapsed. |
-32005 | unauthorized | Missing, invalid, or revoked credentials. |
-32601 | method_unknown | The method name was not recognised on the polygon chain. |
A missing block or an out-of-range index is not an error — it returns
result: null. See the shared Errors reference for the full
envelope, the HTTP-status mapping, and error.data field definitions.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/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_getTransactionByBlockNumberAndIndex",
params: ["latest", "0x0"],
}),
});
const { result, error } = await res.json();
if (error) throw new Error(`${error.code}: ${error.message}`);
console.log(result === null ? "no such transaction" : result.hash);TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ token: process.env.TRIPORT_API_KEY! });
type Transaction = { hash: string; from: string; to: string | null; value: string };
const tx = await client.polygon.rpc<Transaction | null>(
"eth_getTransactionByBlockNumberAndIndex",
["0x3b9aca00", "0x0"],
);
console.log(tx?.hash ?? "no such transaction");Python (triport-sdk)
import os
from triport import Triport
client = Triport(token=os.environ["TRIPORT_API_KEY"])
tx = client.polygon.rpc(
"eth_getTransactionByBlockNumberAndIndex",
["latest", "0x0"],
)
print(tx["hash"] if tx else "no such transaction")Notes
- Zero-based index.
0x0is the first transaction in the block. Useeth_getBlockTransactionCountByNumberto learn the valid index range first. - Null on miss. An out-of-range index or a non-existent block returns
result: null, not an error — guard fornullbefore reading fields. - Hex numerics.
value,gas,gasPrice,nonce, … are hex strings; convert with base 16 before doing arithmetic. Values are in wei. - Polygon chain ID.
chainIdis0x89(137) for Polygon mainnet. - No daily cap. Rate limiting is sustained-rps-per-tier with a 2× burst allowance — there is no daily quota. See Rate limits.
- Related:
eth_getTransactionByBlockHashAndIndex(same lookup, by block hash) ·eth_getTransactionByHash(by transaction hash) ·eth_getBlockByNumber(the whole block at once).