⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_getTransactionReceipt

Returns the receipt of a transaction by transaction hash on Avalanche C-Chain.

When to Use This Method

eth_getTransactionReceipt is essential for:

  • Transaction Confirmation - Check if transaction was successful
  • Event Log Retrieval - Get contract event logs from transaction
  • Gas Usage Analysis - See actual gas used vs estimated
  • Error Debugging - Retrieve revert reasons and failure details

Parameters

  1. Transaction Hash - DATA, 32 bytes
    • The hash of the transaction to get receipt for
    • Format: 0x prefixed, 64 hex characters
{
"jsonrpc": "2.0",
"method": "eth_getTransactionReceipt",
"params": [
"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
],
"id": 1
}

Returns

Object - A transaction receipt object, or null when no receipt was found:

  • transactionHash - 32-byte hash of the transaction
  • transactionIndex - Position in the block
  • blockHash - Hash of the block containing the transaction
  • blockNumber - Block number in hex
  • from - Address of the sender
  • to - Address of the receiver (null for contract creation)
  • cumulativeGasUsed - Total gas used in block up to this transaction
  • gasUsed - Gas used by this specific transaction
  • contractAddress - Address of contract created (if any)
  • logs - Array of log objects generated by this transaction
  • status - 1 for success, 0 for failure
  • effectiveGasPrice - Actual gas price paid

Implementation Examples

curl -X POST https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionReceipt",
"params": [
"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
],
"id": 1
}'

Response Example

Successful Response

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"transactionHash": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238",
"transactionIndex": "0x1",
"blockHash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"blockNumber": "0xb",
"from": "0xaff3454fce5edbc8cca8697c15331677e6ebcccc",
"to": "0xfff7ac99c8e4feb60c9750054bdc14a3b2f0fb8",
"cumulativeGasUsed": "0x33bc",
"gasUsed": "0x4dc",
"contractAddress": null,
"logs": [
{
"address": "0xfff7ac99c8e4feb60c9750054bdc14a3b2f0fb8",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebcccc",
"0x000000000000000000000000eff8bf1e28ffb1bfa76b6dc3e619d5a6e3b6b9b9"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000000a"
}
],
"status": "0x1",
"effectiveGasPrice": "0x4a817c800"
}
}

Common Use Cases

1. Transaction Status Monitoring

Monitor transaction status in real-time:

class TransactionMonitor {
constructor(provider) {
this.provider = provider;
this.monitoring = new Map();
}

async startMonitoring(txHash, callback) {
if (this.monitoring.has(txHash)) {
return; // Already monitoring
}

const monitor = setInterval(async () => {
try {
const receipt = await this.provider.getTransactionReceipt(txHash);

if (receipt) {
clearInterval(monitor);
this.monitoring.delete(txHash);

callback({
success: receipt.status === 1,
receipt,
gasUsed: receipt.gasUsed.toString(),
blockNumber: receipt.blockNumber,
logs: receipt.logs
});
}
} catch (error) {
console.error('Error monitoring transaction:', error);
}
}, 1000); // Check every second

this.monitoring.set(txHash, monitor);
}

stopMonitoring(txHash) {
const monitor = this.monitoring.get(txHash);
if (monitor) {
clearInterval(monitor);
this.monitoring.delete(txHash);
}
}
}

2. Event Log Processing

Process contract events from transaction receipts:

async function processTransactionEvents(txHash) {
const receipt = await provider.getTransactionReceipt(txHash);

if (!receipt || !receipt.logs) {
return { events: [], status: 'no_events' };
}

const events = [];

// Process each log
for (const log of receipt.logs) {
// ERC20 Transfer event signature
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';

if (log.topics[0] === transferTopic && log.topics.length >= 3) {
events.push({
type: 'Transfer',
contract: log.address,
from: '0x' + log.topics[1].slice(26),
to: '0x' + log.topics[2].slice(26),
value: BigInt(log.data).toString()
});
}

// Add more event types as needed
}

return {
events,
status: receipt.status === 1 ? 'success' : 'failed',
gasUsed: receipt.gasUsed.toString(),
blockNumber: receipt.blockNumber
};
}

3. Gas Optimization Analysis

Analyze gas usage patterns:

async function analyzeGasOptimization(txHashes) {
const analyses = [];

for (const txHash of txHashes) {
const receipt = await provider.getTransactionReceipt(txHash);
const tx = await provider.getTransaction(txHash);

if (receipt && tx) {
const gasUsed = Number(receipt.gasUsed);
const gasLimit = Number(tx.gasLimit);
const efficiency = (gasUsed / gasLimit) * 100;

analyses.push({
txHash,
gasLimit,
gasUsed,
efficiency: efficiency.toFixed(2) + '%',
status: receipt.status === 1 ? 'Success' : 'Failed',
gasSaved: gasLimit - gasUsed,
recommendation: efficiency > 95 ? 'Consider increasing gas limit' :
efficiency < 50 ? 'Gas limit too high' : 'Optimal'
});
}
}

// Calculate overall statistics
const avgEfficiency = analyses.reduce((sum, a) =>
sum + parseFloat(a.efficiency), 0) / analyses.length;

return {
transactions: analyses,
stats: {
totalTransactions: analyses.length,
avgEfficiency: avgEfficiency.toFixed(2) + '%',
successRate: (analyses.filter(a => a.status === 'Success').length / analyses.length * 100).toFixed(2) + '%'
}
};
}

4. Contract Creation Detection

Detect and analyze contract deployments:

async function analyzeContractDeployment(txHash) {
const receipt = await provider.getTransactionReceipt(txHash);
const tx = await provider.getTransaction(txHash);

if (!receipt || !tx) {
throw new Error('Transaction not found');
}

// Check if it's a contract creation
if (receipt.contractAddress) {
// Get contract code to verify deployment
const code = await provider.getCode(receipt.contractAddress);

return {
isContractDeployment: true,
contractAddress: receipt.contractAddress,
deploymentSuccessful: code !== '0x' && receipt.status === 1,
deployerAddress: tx.from,
gasUsedForDeployment: receipt.gasUsed.toString(),
blockNumber: receipt.blockNumber,
constructorEvents: receipt.logs.length
};
}

return {
isContractDeployment: false,
transactionType: 'regular_transaction'
};
}

Performance Optimization

Receipt Caching

Cache transaction receipts (they're immutable once mined):

class ReceiptCache {
constructor() {
this.cache = new Map();
}

async getReceipt(provider, txHash) {
if (this.cache.has(txHash)) {
return this.cache.get(txHash);
}

const receipt = await provider.getTransactionReceipt(txHash);

// Only cache confirmed receipts
if (receipt && receipt.blockNumber) {
this.cache.set(txHash, receipt);
}

return receipt;
}

clear() {
this.cache.clear();
}
}

Batch Receipt Queries

Query multiple receipts efficiently:

async function batchGetReceipts(txHashes) {
const batch = txHashes.map((hash, i) => ({
jsonrpc: '2.0',
method: 'eth_getTransactionReceipt',
params: [hash],
id: i
}));

const response = await fetch('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(batch)
});

const results = await response.json();
return results.map((r, i) => ({
txHash: txHashes[i],
receipt: r.result
}));
}

Error Handling

Common errors and solutions:

Error CodeDescriptionSolution
-32602Invalid transaction hashEnsure hash is 64 hex chars with 0x prefix
-32000Transaction not foundTransaction may not be mined yet
null resultTransaction pendingWait and retry
async function safeGetTransactionReceipt(txHash, maxRetries = 10) {
for (let i = 0; i < maxRetries; i++) {
try {
const receipt = await provider.getTransactionReceipt(txHash);

if (receipt) {
return { success: true, receipt };
}

// Transaction might be pending
if (i < maxRetries - 1) {
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
}

} catch (error) {
if (error.code === -32602) {
return { success: false, error: 'Invalid transaction hash format' };
}

if (i === maxRetries - 1) {
return { success: false, error: error.message };
}

await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second before retry
}
}

return { success: false, error: 'Transaction not found after maximum retries' };
}

Need help? Contact our support team or check the Avalanche documentation.