The eth_getTransactionByBlockHashAndIndex
method retrieves transaction information for a specific transaction position within a block, identified by the block's hash.
Returns transaction data at the specified index position from a block with the given hash.
Hash of the block containing the transaction
Integer of the transaction index position in the block (hex)
Transaction object, or null when no transaction was found
Hash of the block containing this transaction
Block number containing this transaction (hex)
Address of the sender
Gas provided by the sender (hex)
Gas price provided by the sender (hex)
Maximum fee per gas (post EIP-1559)
Maximum priority fee per gas (post EIP-1559)
Hash of the transaction
Contract code or input data of the transaction
Sender's transaction count at this block (hex)
Address of the receiver, or null for contract creation
Integer of the transaction index position in the block (hex)
Value transferred in wei (hex)
Transaction type (0: legacy, 1: EIP-2930, 2: EIP-1559)
ECDSA recovery ID
ECDSA signature r
ECDSA signature s
Ethereum transactions have evolved through several formats:
Type | Description | EIP | Key Fields |
---|---|---|---|
0x0 | Legacy transactions | Pre-EIP-2718 | gasPrice |
0x1 | Access list transactions | EIP-2930 | gasPrice , accessList |
0x2 | Fee market transactions | EIP-1559 | maxFeePerGas , maxPriorityFeePerGas |
0x7E | Blob transactions | EIP-4844 | Adds blobVersionedHashes , maxFeePerBlobGas |
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6",
"blockNumber": "0x1b4",
"from": "0x687422eea2cb73b5d3e242ba5456b782919afc85",
"gas": "0x4c4b40",
"gasPrice": "0x1",
"hash": "0xc55e2b90168af6972193c1f86fa4d7d7b31a29c156665d15b9cd48618b5177ef",
"input": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a36102c88061010f6000396000f3fe608060405234801561001057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061010f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f43616c6c6572206973206e6f74206f776e65720000000000000000000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea265627a7a72315820f397f2733a89198bc7fed0764083694c5b828791f39ebcbc9e414bccef14b48064736f6c63430005100032",
"nonce": "0x4",
"to": null,
"transactionIndex": "0x0",
"value": "0x0",
"type": "0x0",
"v": "0x1b",
"r": "0x9db4a2414dcfac7e25b6c0fc771a4fbe5a582f640f6f8ed673970e318494e674",
"s": "0x6cf121d02b5fcd61cec1b8a295b9006c7b137c39162386d968e9310cc2c81b83"
}
}
The transaction object returned by this method contains important fields:
Gas and fee fields vary by transaction type:
The transaction signature consists of three parts:
You can identify contract creation transactions by checking if the to
field is null. For example:
async function isContractCreation(blockHash, txIndex) {
const tx = await ethereum.request({
method: 'eth_getTransactionByBlockHashAndIndex',
params: [blockHash, txIndex]
});
return tx.to === null;
}
For contract creation transactions, the contract address can be derived from:
from
)This method differs from other transaction lookup methods:
Method | Lookup Key | Use Case |
---|---|---|
eth_getTransactionByHash | Transaction hash | Direct transaction lookup when hash is known |
eth_getTransactionByBlockHashAndIndex | Block hash + index | When block hash and tx position are known |
eth_getTransactionByBlockNumberAndIndex | Block number + index | When block number and tx position are known |
The block hash-based method provides absolute certainty that you're querying the right block, even in reorg situations, while the block number method is more convenient for sequential access patterns.