For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_getTransactionByBlockHashAndIndex - Optimism

Example code for the eth_getTransactionByBlockHashAndIndex json-rpc method. Сomplete guide on how to use eth_getTransactionByBlockHashAndIndex json-rpc in GetBlock.io Web3 documentation.

This method retrieves a specific transaction from a block by combining the block's hash with the transaction's index position within that block. The index is zero-based, so the first transaction has index 0. This is useful when you need to access transactions in order within a block or iterate through all transactions in a specific block.

Parameters

Parameter
Type
Description
Required

blockHash

DATA, 32 Bytes

The hash of a block.

Yes

transactionIndex

QUANTITY

The transaction index position in hexadecimal.

Yes

Request Sample

curl --location 'https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
   "jsonrpc": "2.0",
       "method": "eth_getTransactionByBlockHashAndIndex",
 "params": [
"0x90caa11f7bec1b9836af2ff235ccce608fbd826b6c3dbc7928ffe94869c59da2",
"0x0"
    ],
    "id": "getblock.io"
}'
import axios from 'axios'
let data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByBlockHashAndIndex",
 "params": [
"0x90caa11f7bec1b9836af2ff235ccce608fbd826b6c3dbc7928ffe94869c59da2",
"0x0"
    ],
    "id": "getblock.io"
};

let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>",
  headers: {
    "Content-Type": "application/json",
  },
  data: data,
};

axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Response

A successful response returns the following:

Response Parameters

Field
Type
Description

hash

string

Transaction hash

blockHash

string

Hash of the block this transaction belongs to

blockNumber

string (hex)

Block number

from

string

Address that initiated the transaction

to

string or null

Recipient address or null for contract creation

value

string (hex)

Amount transferred in wei

nonce

string (hex)

Number of transactions sent by the sender

gas

string (hex)

Gas limit

gasPrice

string (hex)

Gas price in wei

input

string (hex)

Transaction calldata

transactionIndex

string (hex)

Index of this transaction in the block

v, r, s

string

Signature fields

Use Case

Error handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS_TOKEN.

-32602

Invalid argument

  • The block hash does not exist

  • Index is not a proper hex integer

  • Block does have transaction at that index

Integration with Web3

The eth_getTransactionByBlockHashAndIndex method helps developers to:

  • Build richer block explorers that display ordered transaction lists

  • Generate analytics around transaction distribution inside blocks

  • Debug transactions by locating their exact place in the block

  • Power DeFi dashboards and monitoring tools that react to specific activity

  • Build trustless frontends that fetch live block data without running a node

Last updated

Was this helpful?