eth_getTransactionByHash - Optimism

This method retrieves comprehensive transaction data, including the sender, recipient, value, gas parameters, input data, and block information. It's one of the most commonly used methods for tracking transaction status and retrieving transaction details. The method returns null if the transaction is not found. On Optimism, the transaction object may include additional L2-specific fields.

Parameters

ParameterTypeDescriptionRequired
transactionHashDATA, 32 BytesThe hash of a transaction.Yes

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_getTransactionByHash",
    "params": ["0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"],
    "id": "getblock.io"
}'
bashconst axios = require('axios');

const url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/";
const headers = { "Content-Type": "application/json" };

const payload = {
    jsonrpc: "2.0",
    method: "eth_getTransactionByHash",
    params: ["0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"],
    id: "getblock.io"
};

axios.post(url, payload, { headers })
    .then(response => {
        if (response.status === 200) {
            console.log("eth_getTransactionByHash result:", response.data.result);
        } else {
            console.error("Error:", response.status, response.statusText);
        }
    })
    .catch(error => {
        console.error("Error:", error.response ? error.response.data : error.message);
    });
pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
headers = {
    "Content-Type": "application/json"
}
payload = {
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByHash",
    "params": ["0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"],
    "id": "getblock.io"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    result = response.json().get("result")
    print("eth_getTransactionByHash result:", result)
else:
    print("Error:", response.status_code, response.text)
rsimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
headers = {
    "Content-Type": "application/json"
}
payload = {
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByHash",
    "params": ["0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"],
    "id": "getblock.io"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    result = response.json().get("result")
    print("eth_getTransactionByHash result:", result)
else:
    print("Error:", response.status_code, response.text)

Response

A successful response returns the following:

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "blockHash": "0x3e4a6a9efc7e4db75269430a5683ae3c7505ab0848d7814bd1c73c76e6882467",
        "blockNumber": "0x9087826",
        "blockTimestamp": "0x6a04ca05",
        "from": "0xcde377407d9b819efc0e185aa2d442194c2233e6",
        "gas": "0x27ac40",
        "gasPrice": "0x15f",
        "maxFeePerGas": "0x5f5e100",
        "maxPriorityFeePerGas": "0x1",
        "hash": "0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685",
        "input": "0x83730cc30000000000000000000000000000000000000000000000000000000009087826",
        "nonce": "0xb1ebba",
        "to": "0x4aed348173bbf17dfaeb91598321904c9323d36e",
        "transactionIndex": "0x23",
        "value": "0x0",
        "type": "0x2",
        "accessList": [],
        "chainId": "0xa",
        "v": "0x1",
        "r": "0x4d68c5f11ba8c7803a3abe897b9ba8956e0938bf9338e2467ebc0b10996b85cd",
        "s": "0x5e76ac945fa081a13869c9f3adb9f5484b0b89f074322ec5015ef913b0bb6e0a",
        "yParity": "0x1"
    }
}

Response Parameters

FieldTypeDescription
hashstringHash of the transaction
blockHashstring or nullHash of the block that contains this transaction. Null if pending
blockNumberstring or nullBlock number in hex. Null if pending
transactionIndexstring or nullIndex of this transaction in the block
fromstringSender address
tostring or nullReceiver address. Null for contract creation
valuestring (hex)Amount sent in wei
noncestring (hex)Counter of transactions sent by the sender
gasstring (hex)Gas limit for the transaction
gasPricestring (hex)Gas price in wei
inputstring (hex)Calldata or contract code
v, r, sstringTransaction signature components

Use Case

The eth_getTransactionByHash method is commonly used for:

  • Transaction tracking
  • Payment verification
  • Debugging transactions
  • Transaction history display

Error handling

Status CodeError MessageCause
404Not FoundMissing or invalid ACCESS_TOKEN.
-32602Invalid argument<ul><li>Transaction hash is invalid</li></ul>

Integration with Web3

The eth_getTransactionByHash method helps developers to:

  • Build trustless frontends that check transaction status directly
  • Track pending, failed, or confirmed transactions in real time
  • Support dashboards, DeFi interfaces, wallets, and explorers
  • Read transaction calldata for analytics and debugging
  • Improve UX by notifying users instantly when their transaction is included
  • Verify transaction ordering for MEV, priority fees, and gas bidding strategies
javascriptimport { ethers } from "ethers";
const RPC_URL = "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>";
const provider = new ethers.JsonRpcProvider(RPC_URL);
async function Call() {
  try {
     const result = await provider.send("eth_getTransactionByHash",
    [
        "0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"
    ]);    
console.log("The result:", result);
    return result;
  } catch (error) {
    console.error("The error:", error);
    throw error;
  }
}
jsximport { createPublicClient, http } from 'viem';
import { optimism } from 'viem/chains';

// Create Viem client with GetBlock
const client = createPublicClient({
  chain: optimism,
  transport: http('https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>'),
});

// Using the method through Viem
async function Call() {
    try {
        // Method-specific Viem implementation
        const result = await client.request({
         method: "eth_getTransactionByHash",
         params: [
        "0xca5a3c6bcb4a1ddf5e762687816b82dbcf869b8c5a4d7301b65f33f8b0f53685"
    ],
        });
        console.log('Result:', result);
        return result;
    } catch (error) {
        console.error('Viem Error:', error);
        throw error;
    }
}