Ethereum's eth_getTransactionByHash API method retrieves detailed information about a specific transaction using its unique hash. This JSON-RPC call returns an object containing sender/recipient addresses, gas metrics, transaction value, and other blockchain metadata—essential for auditing, analytics, and transaction tracking.
👉 Master Ethereum APIs with OKX's developer resources
Core Parameters and Response Structure
Required Parameter
hash(string):
The 66-character transaction hash starting with0x
Transaction Response Object
| Field | Description |
|---|---|
blockHash | Block containing the transaction (null if pending) |
blockNumber | Block height (null if pending) |
from | Sender's Ethereum address |
gas | Gas units provided by sender |
maxFeePerGas | Max fee per gas unit (EIP-1559) |
hash | Transaction's unique identifier |
input | Smart contract call data (if applicable) |
value | Transferred ETH in Wei |
Practical Implementation
Ethers.js Example
const ethers = require("ethers");
const provider = new ethers.JsonRpcProvider("YOUR_RPC_URL");
async function fetchTransaction(txHash) {
const tx = await provider.send("eth_getTransactionByHash", [txHash]);
console.log(`Sender: ${tx.from}`);
console.log(`Block: ${tx.blockNumber || 'Pending'}`);
console.log(`Value: ${ethers.formatEther(tx.value)} ETH`);
}
fetchTransaction("0xb528d7...6099e");Key Use Cases
- Transaction Auditing
Verify execution details like gas consumption and block inclusion - Wallet Activity Monitoring
Track outgoing/incoming transfers programmatically - Block Explorer Backends
Power transaction detail pages in blockchain explorers
FAQ
Q: Why does my transaction return null fields?
A: blockHash, blockNumber, and transactionIndex remain null for pending transactions until mined.
Q: How do I convert Wei to ETH?
A: Use libraries like Ethers.js: ethers.formatEther(valueInWei)
Q: What's the difference between gasPrice and maxFeePerGas?
A: gasPrice is for legacy transactions, while maxFeePerGas applies to EIP-1559 transactions.
👉 Explore Ethereum development tools on OKX
Advanced Considerations
- MEV Protection Impact: Transactions routed through private pools may not appear immediately
- Signature Analysis: The
v,r,sfields enable ECDSA signature verification - Type 2 Transactions: EIP-1559 transactions show
type: 2with dynamic fee structure