eth_getTransactionByBlockHashAndIndex - Ethereum

This method returns transaction data by block hash and transaction index within that block. Useful when iterating through a block's transactions without needing to first fetch the full block object.

Parameters

ParameterTypeRequiredDescription
blockHashstringYes32-byte block hash
transactionIndexstringYesHex-encoded transaction index within the block (0-based)

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByBlockHashAndIndex",
    "params": [
        "0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c",
        "0x0"
    ],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_getTransactionByBlockHashAndIndex',
    params: [
        "0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c",
        "0x0"
    ],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_getTransactionByBlockHashAndIndex',
        'params': [
        "0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c",
        "0x0"
    ],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_getTransactionByBlockHashAndIndex",
            "params": [
        "0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c",
        "0x0"
    ],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "hash": "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b",
        "nonce": "0x462",
        "blockHash": "0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c",
        "blockNumber": "0x1720340",
        "transactionIndex": "0x0",
        "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
        "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "value": "0x0",
        "gas": "0x186a0",
        "gasPrice": "0x9502f900",
        "maxFeePerGas": "0xb2d05e00",
        "maxPriorityFeePerGas": "0x3b9aca00",
        "input": "0xa9059cbb000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000de0b6b3a7640000",
        "v": "0x0",
        "r": "0xa3b4c5d6e7f8091a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a",
        "s": "0xb6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7",
        "chainId": "0x1",
        "type": "0x2",
        "accessList": [],
        "yParity": "0x0"
    }
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
result.hashstringTransaction hash
result.noncestringNonce of the sender at the time of signing
result.blockHashstringHash of the block containing this transaction (null if pending)
result.blockNumberstringBlock number containing this transaction (null if pending)
result.transactionIndexstringPosition of this transaction within its block (null if pending)
result.fromstringSender address
result.tostringRecipient address (null for contract creation)
result.valuestringValue transferred (wei, hex)
result.gasstringGas limit for this transaction
result.gasPricestringEffective gas price (wei, hex)
result.maxFeePerGasstringEIP-1559 maximum total fee per gas (type-2 transactions)
result.maxPriorityFeePerGasstringEIP-1559 priority fee per gas (type-2 transactions)
result.inputstringEncoded call data
result.vstringSignature v value
result.rstringSignature r value
result.sstringSignature s value
result.chainIdstringChain ID the transaction is bound to (EIP-155)
result.typestringTransaction type (0x0 legacy, 0x1 EIP-2930, 0x2 EIP-1559, 0x3 EIP-4844 blob, 0x4 EIP-7702 SetCode)
result.accessListarray of objectEIP-2930 access list (type-1+ transactions)
result.yParitystringSignature parity (post-London)

Use Cases

  • Reorg-Safe Transaction Iteration: Iterate through a block's transactions by hash (immune to reorg confusion versus block-number lookups)
  • MEV Bundle Analysis: Fetch specific top-of-block transactions (indices 0-3) to analyze block-space auctions
  • Positional Analytics: Study where in a block certain contract calls appear (front-run vs back-run positions)

Error Handling

Error CodeMessageDescription
-32602Invalid paramsBlock hash is malformed or transaction index is out of range
-32603Internal errorNode failed to look up the block or transaction

Web3 Integration

ethers-example.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const tx = await provider.send('eth_getTransactionByBlockHashAndIndex', ['0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c', '0x0']);
console.log('First transaction in block:', tx.hash);
console.log('From:', tx.from, '→ To:', tx.to);

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';

const client = createPublicClient({
    chain: mainnet,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/'),
});

const tx = await client.getTransaction({
    blockHash: '0x9ec8e2f6b78d8f5f2ac3e5d61b0d38d4d5a8f0e7c8b5a2f9d3e6c1b7a4d0f2e5c',
    index: 0,
});
console.log('First transaction in block:', tx.hash);