eth_getTransactionByBlockHashAndIndex
https://api.triport.io/polygonReturns a single Polygon transaction by the hash of its block and its zero-based position within that block.
eth_getTransactionByBlockHashAndIndex looks up a Polygon block by its 32-byte
hash and returns the one transaction sitting at the supplied zero-based index
within that block. The transaction comes back as the standard Ethereum/Bor
transaction object.
Use it when you already hold a block hash — from a log, a receipt's blockHash,
or a prior eth_getBlockByHash response — and want to walk that block's
transactions one at a time without downloading the full block body. It is a
common primitive for block-by-block indexers: pair it with
eth_getBlockTransactionCountByHash
to read the transaction count, then iterate 0x0 … count-1, fetching each
transaction by index. Addressing by hash (rather than by number) is unambiguous —
a hash pins exactly one block even across a reorganization.
If the block hash is unknown to the node (for example a block it has not yet
seen, or one orphaned by a reorg) or the index is out of range for the block,
the method succeeds and returns null rather than an error. Always check for
null before reading fields off the result.
Parameters
Positional params array: [blockHash, index].
blockHashstring (32-byte hex)required0x-prefixed (66 characters total).indexstring (hex)required0x-prefixed hexadecimal integer (e.g. 0x0 for the first transaction).Response
When the block hash is unknown or the index is out of range, the result is
null:
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}hashstring (hex)blockHashstring (hex)blockNumberstring (hex)0x-prefixed.transactionIndexstring (hex)index).noncestring (hex)fromstring (hex)tostring (hex) | nullnull for a contract-creation transaction.valuestring (hex)gasstring (hex)gasPricestring (hex)maxFeePerGasstring (hex)0x2 transactions).maxPriorityFeePerGasstring (hex)0x2 transactions).inputstring (hex)typestring (hex)0x0 legacy, 0x1 access-list, 0x2 EIP-1559.chainIdstring (hex)0x89 (137) for Polygon mainnet.v, r, sstring (hex)Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The API key's trial period has ended; upgrade to a paid tier to continue. |
-32002 | tier_insufficient | The key's tier is below the level required for this method. |
-32003 | rate_limited | Per-tier RPS limit exceeded (15 / 20 / 100 / 250 RPS for free / basic / pro / business). Back off and retry. |
-32004 | subscription_expired | The subscription tied to the key has lapsed. |
-32005 | unauthorized | Missing, malformed, or invalid API key. |
-32601 | method_unknown | The method name is not recognized on this path. |
An unknown block hash or an out-of-range index is not an error — it is
reported as result: null (see above). Every error follows the shared JSON-RPC
error envelope — see Errors for the full structure and
handling guidance.
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_getTransactionByBlockHashAndIndex",
params: [
"0x9b7f2a3c1d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcd",
"0x0",
],
}),
});
const { result } = await res.json();
console.log(result === null ? "no transaction at that index" : result.hash);TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const triport = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const tx = await triport.polygon.getTransactionByBlockHashAndIndex(
"0x9b7f2a3c1d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcd",
"0x0",
);
console.log(tx === null ? "no transaction at that index" : tx.hash);Python (triport-sdk)
import os
from triport import Triport
triport = Triport(api_key=os.environ["TRIPORT_API_KEY"])
tx = triport.polygon.get_transaction_by_block_hash_and_index(
"0x9b7f2a3c1d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcd",
"0x0",
)
print("no transaction at that index" if tx is None else tx["hash"])Notes
indexis hex, not decimal. Pass0x0,0x1, … — not0,1.- Always handle
null. An unknown block hash or an out-of-range index returnsresult: nullrather than an error. Guard for it before reading any field. - Indexer iteration pattern. Read the transaction count with
eth_getBlockTransactionCountByHash, then request indices0x0throughcount-1. When you need every transaction in a block at once, fetching the full block witheth_getBlockByHash(fullTxBodies = true) is cheaper than many per-index calls. - EIP-1559 fee fields.
maxFeePerGasandmaxPriorityFeePerGasappear only on type0x2transactions; legacy transactions exposegasPriceonly. - Rate limiting is RPS-per-tier with a burst allowance; there is no daily
quota. A
-32003 rate_limitedresponse means you should back off and retry shortly. - Related methods:
eth_getTransactionByBlockNumberAndIndex(same lookup by block number),eth_getTransactionByHash(look up directly by transaction hash),eth_getBlockTransactionCountByHash.