Retrieve transaction details by transaction hash using eth_getTransactionByHash. Essential for tracking and verifying individual transactions on the Ethereum blockchain.
This method returns transaction information for the specified transaction hash, allowing developers to retrieve detailed data about specific transactions
The Ethereum eth_getTransactionByHash method is part of the Ethereum JSON RPC Core API, used to interact with Ethereum nodes. The eth_getTransactionByHash RPC Ethereum method is crucial for tracking and verifying individual transactions.
Supported Networks
The eth_getTransactionByHash RPC Ethereum method supports the following network types:
Mainnet
Testnet: Sepolia, Holesky
Parameters
DATA: The 32-byte hash transaction.
Request
URL (API Endpoint)
https://go.getblock.io/<ACCESS-TOKEN>/
To make a request, send a JSON object with the jsonrpc, method, and params fields. Below is an example of how to make a request using curl:
wscat -c wss://eth.getblock.io/YOUR-API-KEY/ # wait for connection and send the request body {"jsonrpc":"2.0","method":"eth_getTransactionByHash","params": ["0xcd718a69d478340dc28fdf6bf8056374a52dc95841b44083163ced8dfe29310c"],"id":"getblock.io"}
Response
The server responds with a JSON object containing the transaction details for the specified hash. Below is an example of a typical response:
accessList: A list of addresses and storage keys the transaction accesses (EIP-2930).
blockHash: The hash of the block containing the transaction.
blockNumber: The number of the block containing the transaction.
chainId: The chain ID of the Ethereum network.
from: The address of the sender.
gas: The gas provided by the sender.
gasPrice: The gas price provided by the sender in Wei.
hash: The hash of the transaction.
input: The input data for the transaction.
maxFeePerGas: Maximum fee per gas that the sender is willing to pay.
maxPriorityFeePerGas: Maximum priority fee per gas.
nonce: The number of transactions made by the sender prior to this one.
r, s, v: Components of the transaction signature.
to: The address of the receiver.
transactionIndex: The index position of the transaction within the block.
type: The transaction type.
value: The value transferred in Wei.
Use Case
The eth_getTransactionByHash method is particularly useful for retrieving detailed information about a specific transaction, which can be critical for verifying and tracking transactions on the Ethereum blockchain. In case of an eth_getTransactionByHash error, developers should verify that the provided transaction hash is correct and corresponds to an existing transaction. An eth_getTransactionByHash example can help developers understand the correct usage of this method.
Code Example
You can also make requests to the eth_getTransactionByHash method programmatically using Python. Below is an example using the requests library:
import requestsimport json# Define the API URL and access tokenurl ='https://go.getblock.io/<ACCESS-TOKEN>/'headers ={'Content-Type':'application/json'}# Prepare the request datadata ={"jsonrpc":"2.0","method":"eth_getTransactionByHash","params": ["0xcd718a69d478340dc28fdf6bf8056374a52dc95841b44083163ced8dfe29310c" ],"id":"getblock.io"}# Send the POST requestresponse = requests.post(url, headers=headers, data=json.dumps(data))# Parse the JSON responseresponse_data = response.json()# Print the resultprint(json.dumps(response_data, indent=4))
constaxios=require('axios');// Replace YOUR-API-KEY with your actual API keyconsturl='https://go.getblock.io/YOUR-API-KEY/';// Request payloadconstpayload= { jsonrpc:'2.0', method:'eth_getTransactionByHash', params: ['0xcd718a69d478340dc28fdf6bf8056374a52dc95841b44083163ced8dfe29310c',// Transaction hash ], id:'getblock.io',};// Axios POST requestaxios.post(url, payload, { headers: {'Content-Type':'application/json', }, }).then((response) => {console.log('Response:',response.data); }).catch((error) => {console.error('Error:',error.message); });
This Python script sends a request to the eth_getTransactionByHash method and prints the returned transaction information. Make sure to replace <ACCESS-TOKEN> with your actual API token. This script serves as an eth_getTransactionByHash example for developers to understand the implementation in Python.
The Web3 eth_getTransactionByHash method can also be used in Web3 libraries for Ethereum, providing an interface to access detailed transaction data based on a specific transaction hash.