eth_getTransactionByBlockHashAndIndex
https://api.triport.io/v1/ethereumReturns the transaction at a given position inside the block identified by its block hash.
eth_getTransactionByBlockHashAndIndex locates a block by its 32-byte hash and
returns the single transaction sitting at the supplied zero-based index within
that block. The transaction is returned as the standard Ethereum transaction
object.
Use it when you already hold a block hash — from a log, a receipt, or an
eth_getBlockByHash response — and want to walk that block's transactions one
at a time without downloading the full block body. Pair it with
eth_getBlockTransactionCountByHash:
fetch the count, then iterate 0 … count-1, requesting each transaction by
index.
If the block hash is unknown (e.g. an orphaned/uncle block, or a block the node
has not yet seen) or the index is out of range for the block, the method returns
null instead of an error. Always check for null before reading fields off
the result.
Parameters
Two positional parameters, in order.
blockHashstringrequired0x-prefixed (66 characters total).indexstringrequired0x-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
}hashstringblockHashstringblockNumberstring0x-prefixed hex.transactionIndexstring0x-prefixed hex (echoes the request index).noncestringfromstringtostring | nullnull for a contract-creation transaction.valuestring0x-prefixed hex.gasstringgasPricestringmaxFeePerGasstring0x2 transactions).maxPriorityFeePerGasstring0x2 transactions).inputstringtypestring0x0 legacy, 0x1 access-list, 0x2 EIP-1559.chainIdstring0x1 for Ethereum mainnet).v, r, sstringErrors
| 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. |
A missing block or out-of-range index is not an error — it is reported as
result: null (see above). A -32003 response carries Retry-After and
X-RateLimit-Reset headers plus a data object with limit_rps,
burst_capacity, and retry_after_sec. 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_getTransactionByBlockHashAndIndex",
params: [
"0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543",
"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 client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const tx = await client.ethereum.request<Record<string, unknown> | null>(
"eth_getTransactionByBlockHashAndIndex",
[
"0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543",
"0x0",
],
);
console.log(tx === null ? "no transaction at that index" : tx.hash);Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
tx = client.ethereum.request(
"eth_getTransactionByBlockHashAndIndex",
[
"0xb9b8b8b1b0c9e6a0f3d4c5b6a7988e9d0c1b2a3948576f5e4d3c2b1a09876543",
"0x0",
],
)
print("no transaction at that index" if tx is None else tx["hash"])Notes
- The
indexis a hex string (0x0,0x1, …), not a decimal number. - Always handle the
nullcase: an unknown block hash or an out-of-range index returnsresult: nullrather than an error. - EIP-1559 fee fields (
maxFeePerGas,maxPriorityFeePerGas) appear only on type0x2transactions; legacy transactions exposegasPriceonly. - 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 fetch the same transaction by block height instead of hash, use
eth_getTransactionByBlockNumberAndIndex. To look a transaction up directly by its hash, useeth_getTransactionByHash. To learn how many transactions a block holds, useeth_getBlockTransactionCountByHash.