eth_getTransactionByBlockNumberAndIndex
https://api.triport.io/v1/ethereumReturns the transaction at a given position within the block identified by its number or a block tag.
eth_getTransactionByBlockNumberAndIndex returns a single transaction object
selected by two coordinates: the block (by number or block tag) and the
transaction's zero-based index within that block. Both the block number and the
index are 0x-prefixed hexadecimal strings.
Use it when you already know a transaction's position in a block — for example
when iterating a block's transactions one at a time, when you have the index
from a prior eth_getBlockByNumber call, or when reconstructing a block body
without fetching every transaction at once. If you have the block hash rather
than its number, use the sibling method
eth_getTransactionByBlockHashAndIndex. If you have the transaction hash
directly, use eth_getTransactionByHash.
If the block does not exist, or the index is out of range for that block, the
result is null rather than an error.
Parameters
Pass a two-element positional array.
blockParameterstringrequired0x-prefixed hex block number (e.g. 0x149e2c1) or a block 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 contains the standard Ethereum fields:
| Field | Type | Description |
|---|---|---|
blockHash | string | Hash of the containing block, or null if pending. |
blockNumber | string | Block number as 0x-prefixed hex, or null if pending. |
from | string | Sender address. |
to | string | null | Recipient address; null for contract-creation transactions. |
gas | string | Gas supplied, hex. |
gasPrice | string | Effective gas price, hex (in wei). |
maxFeePerGas | string | Max fee per gas, hex — present on EIP-1559 (type 0x2) transactions. |
maxPriorityFeePerGas | string | Max priority fee per gas, hex — present on EIP-1559 transactions. |
hash | string | Transaction hash. |
input | string | Call data, hex. |
nonce | string | Sender nonce, hex. |
transactionIndex | string | Index of the transaction in the block, hex. |
value | string | Value transferred in wei, hex. |
type | string | Transaction type (0x0 legacy, 0x1 access-list, 0x2 EIP-1559). |
chainId | string | Chain ID, hex (0x1 for Ethereum mainnet). |
v, r, s | string | ECDSA signature components, hex. |
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 or index is missing, or not a valid hex value / 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_getTransactionByBlockNumberAndIndex",
params: ["latest", "0x0"],
}),
});
const { result } = await res.json();
console.log(result === null ? "no such transaction" : result.hash);TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
type Transaction = { hash: string; from: string; to: string | null; value: string };
const tx = await client.ethereum.request<Transaction | null>(
"eth_getTransactionByBlockNumberAndIndex",
["0x149e2c1", "0x0"],
);
console.log(tx?.hash ?? "no such transaction");Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
tx = client.ethereum.request(
"eth_getTransactionByBlockNumberAndIndex",
["latest", "0x0"],
)
print(tx["hash"] if tx else "no such transaction")Notes
- The index is zero-based:
0x0is the first transaction in the block. - An out-of-range index or a non-existent block returns
result: null, not an error — check fornullbefore reading fields. - Numeric fields (
value,gas,gasPrice,nonce, …) are hex strings; convert with base 16 before arithmetic. eth_getTransactionByBlockNumberAndIndexis 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 select by block hash instead, use
eth_getTransactionByBlockHashAndIndex. To look up a transaction by its own hash, useeth_getTransactionByHash. To count a block's transactions first, useeth_getBlockTransactionCountByNumber.