eth_getTransactionByBlockNumberAndIndex

Ethereum RPC

Overview

The eth_getTransactionByBlockHashAndIndex is an Ethereum JSON-RPC method that allows you to fetch the transaction details based on the block hash and the index of the transaction within that block. This method can be useful when you want to retrieve transaction details for a specific transaction without knowing its transaction hash.

Usecase

Use cases for this method may include:

  • Inspecting transaction details for debugging purposes
  • Gathering data for transaction analysis
  • Fetching transaction information for specific blocks in a block explorer application

Parameters

The eth_getTransactionByBlockHashAndIndex method accepts two parameters:

  • blockHash (required): The hash of the block containing the transaction.
    • Example: 10123321
  • transactionIndex: (required): The index of the transaction within the specified block. The index is a hexadecimal value.
    • Example: 0

Returns

The method returns a JSON object containing the following fields:

NameDescription
hashThe transaction hash as a 32-byte hex string.
nonceThe number of transactions made by the sender prior to this one.
blockHashThe hash of the block in which this transaction is included.
blockNumberThe block number in which this transaction is included.
transactionIndexThe index of the transaction within the block.
fromThe address of the sender.
toThe address of the recipient. null if the transaction is a contract creation transaction.
valueThe value transferred in wei.
gasPriceThe gas price provided by the sender in wei.
gasThe gas limit provided by the sender.
inputThe data sent along with the transaction.

Request

curl --location 'https://api.tatum.io/v3/blockchain/node/ethereum-mainnet/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_getTransactionByBlockNumberAndIndex",
    "params": [
        10123321,
        0
    ]
}'

// yarn add @tatumio/tatum

import { TatumSDK, Ethereum, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM })

const tx = await tatum.rpc.getTransactionByBlockNumberAndIndex(10123321, 0)

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs