🔍 eth_getTransactionByBlockHashAndIndex - Base Chain JSON-RPC Method
📝 Overview
The eth_getTransactionByBlockHashAndIndex
method retrieves detailed information about a transaction from the Base blockchain by specifying a block hash and the transaction's position (index) within that block.
💡 Block Explorer Alternative: This method provides programmatic access to transaction data similar to what you'd see on a block explorer, but through a direct API call to your Base node.
⚙️ Parameters
Parameter | Type | Description |
---|---|---|
blockHash | String | The 32-byte hash of the block containing the transaction |
index | String | The position of the transaction in the block (hex-encoded integer) |
Need RPC API keys?
Get 12.5M archival requests for free today.
🔄 Returns
Transaction Object with the following fields:
Field | Type | Description |
---|---|---|
blockHash | String | 32-byte hash of the block containing this transaction |
blockNumber | String | Block number (hex) containing this transaction |
from | String | Address of the sender |
gas | String | Gas provided by the sender (hex) |
gasPrice | String | Gas price provided by the sender in wei (hex) |
maxFeePerGas | String | Maximum fee per gas set in the transaction (EIP-1559 only) |
maxPriorityFeePerGas | String | Maximum priority fee per gas (EIP-1559 only) |
hash | String | 32-byte transaction hash |
input | String | Data sent with the transaction |
nonce | String | Number of transactions made by sender before this one (hex) |
to | String | Address of the receiver (null for contract creation) |
transactionIndex | String | Position of the transaction in the block (hex) |
value | String | Value transferred in wei (hex) |
type | String | Transaction type (0=legacy, 1=EIP-2930, 2=EIP-1559) |
accessList | Array | List of addresses and storage keys the transaction plans to access |
chainId | String | Chain ID of the transaction (Base mainnet is 8453) |
v | String | ECDSA recovery ID |
r | String | ECDSA signature r value |
s | String | ECDSA signature s value |
🌐 Request
POST https://base-mainnet.chainnodes.org/YOUR-API-KEY
🧪 Example
- HTTPS POST Request with a JSON RPC call in the body
- Replace YOUR-API-KEY with the API key from your Chainnodes.org Dashboard
- You can use a different supported network by replacing
base-mainnet
curl https://base-mainnet.chainnodes.org/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params": ["0x54751c3cb4f7c95b249ab5ed702a708a6782cc937b1d399f25be4b40d9e0f5d4", "0x0"],"id":1}'
💡 Confusing?
Ask our experienced blockchain developers in Telegram
📊 Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0x54751c3cb4f7c95b249ab5ed702a708a6782cc937b1d399f25be4b40d9e0f5d4",
"blockNumber": "0x57e450",
"from": "0xad89a377e302791fb523ffb427f3f480cad3a72c",
"gas": "0x3362",
"gasPrice": "0xe12c5d1dc",
"maxFeePerGas": "0xe12c5d1dc",
"maxPriorityFeePerGas": "0x5f5e100",
"hash": "0xf02e0576a830ab37f2eb1c43ed3fbcaa53d84bf5ca985ae60c71f5cac27f4cc3",
"input": "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000642f1f1f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x1",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"transactionIndex": "0x0",
"value": "0x0",
"type": "0x2",
"accessList": [],
"chainId": "0x2105",
"v": "0x0",
"r": "0x3b4afab91edec37c0cfe9e68f2d65c4c7e9ab23d3453eaa456bdb41e5d22548f",
"s": "0x217ad72b41a611526a45aae9392affba8114c0bd4c25e8ef7f05cda45ef5cee0"
}
}
🚀 Use Cases
1️⃣ Block Explorer Development
Build your own Base chain block explorer or transaction tracking tool by efficiently retrieving transaction data by block position.
// Iterate through all transactions in a block
async function getAllTransactionsInBlock(blockHash) {
const blockData = await getBlockByHash(blockHash);
const txCount = parseInt(blockData.transactions, 16);
for (let i = 0; i < txCount; i++) {
const txIndex = '0x' + i.toString(16);
// Get each transaction in the block
const tx = await getTxByBlockHashAndIndex(blockHash, txIndex);
processTx(tx);
}
}
2️⃣ Historical Transaction Analysis
Analyze transaction patterns and activity on Base chain by examining consecutive transactions within specific blocks.
// Analyze transactions from a significant block
{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0x54751c3cb4f7c95b249ab5ed702a708a6782cc937b1d399f25be4b40d9e0f5d4","0x0"],"id":1}
3️⃣ Gas Price Monitoring
Track gas prices over time by analyzing transactions at regular block intervals on Base.
// Get first transaction from blocks at different heights to track gas price trends
{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x57e450",false],"id":1}
// Then for each block hash:
{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0xBlockHash","0x0"],"id":1}
4️⃣ MEV and Front-Running Detection
Examine transaction ordering within blocks to detect potential MEV (Maximal Extractable Value) or front-running activity on Base.
// Get all transactions in a block to analyze ordering patterns
{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0x54751c3cb4f7c95b249ab5ed702a708a6782cc937b1d399f25be4b40d9e0f5d4",false],"id":1}
// Then for suspicious blocks, examine transactions individually:
{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0x54751c3cb4f7c95b249ab5ed702a708a6782cc937b1d399f25be4b40d9e0f5d4","0x1"],"id":1}
5️⃣ Cross-Chain Transaction Comparison
Compare transaction structures between Ethereum mainnet and Base transactions to understand L2-specific patterns.
// Get Base chain transaction
{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0xBaseBlockHash","0x0"],"id":1}
// Then compare with Ethereum mainnet transaction
🔗 Related Methods
- eth_getTransactionByHash - Get transaction by hash
- eth_getTransactionByBlockNumberAndIndex - Get transaction by block number and index
- eth_getBlockByHash - Get block information by hash
📚 Base Chain Transaction Notes
🔢 Chain ID: Base mainnet transactions have chain ID 8453 (0x2105 in hex), while Base Goerli testnet uses 84531. This is visible in the
chainId
field of the transaction.
🌉 L1 Data Fees: Transactions on Base include an L1 data fee component that's not found on Ethereum mainnet. This is because Base posts transaction data to Ethereum as part of its rollup design.
💨 Gas Pricing: Base has different gas dynamics than Ethereum, often with lower base fees, though the transaction structure with
maxFeePerGas
andmaxPriorityFeePerGas
remains the same.
📝 Transaction Types: Base supports the same transaction types as Ethereum mainnet: Legacy (type 0), EIP-2930 (type 1), and EIP-1559 (type 2).