eth_getTransactionByBlockNumberAndIndex - Optimism

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

This method retrieves a specific transaction from a block by combining the block number with the transaction's index position. This is commonly used to iterate through transactions in a block or to access transactions at specific positions. You can use block tags like 'latest' as well.

Parameters

Parameter
Type
Description
Required

blockNumber

QUANTITY|TAG

Block number in hex, or 'latest', 'earliest', 'pending'.

Yes

transactionIndex

QUANTITY

The transaction index position in hexadecimal.

Yes

Request Sample

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByBlockNumberAndIndex",
    "params": ["0x7A69B2C", "0x0"],
    "id": "getblock.io"
}'

Response

A successful response returns the following:

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "blockHash": "0x1ff2fcd80ed93d75855364f7e879795dbd5790210c5224ad2c1083d9744297d6",
        "blockNumber": "0x7a69b2c",
        "blockTimestamp": "0x67411011",
        "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001",
        "gas": "0xf4240",
        "gasPrice": "0x0",
        "hash": "0x4fae8f6c70a4f50cf8894bf9847ed364922826658c3cb73e291e03934637a853",
        "input": "0x440a5e200000146b000f79c500000000000000040000000067410f83000000000144320300000000000000000000000000000000000000000000000000000002fe2cca3c00000000000000000000000000000000000000000000000000000000001f11bf37aac56bf514562b0ee38600119c0a4f70b20f0c6abc66a2011d1bdd9b18cb1c0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985",
        "nonce": "0x160d8b6",
        "to": "0x4200000000000000000000000000000000000015",
        "transactionIndex": "0x0",
        "value": "0x0",
        "type": "0x7e",
        "v": "0x0",
        "r": "0x0",
        "s": "0x0",
        "sourceHash": "0xf14ecb423df1f95f609d9781126cdd9ea4d248f4502c083507b2f1f72aa779a8",
        "mint": "0x0",
        "depositReceiptVersion": "0x1"
    }
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: A transaction object with all transaction details, or null if not found.

Use Case

The eth_getTransactionByBlockNumberAndIndex method is commonly used for:

  • Transaction iteration

  • Block processing

  • Sequential access patterns

Error handling

Status Code
Error Message
Cause

404

Not Found

Missing or invalid ACCESS_TOKEN.

-32602

Invalid argument

  • The block number does not exist or is beyond the chain height

  • Index is not a valid hex integer

  • Block does have transaction at that index

Integration with Web3

The eth_getTransactionByBlockNumberAndIndex method helps developers:

  • Build trustless UIs that load transaction lists directly from RPC

  • Power dashboards analyzing block activity and congestion

  • Support exchanges, wallets, and bridges that track transaction placement

  • Generate block-level historical analytics

  • Verify transaction ordering for MEV, priority fees, and gas bidding strategies

Last updated

Was this helpful?