# eth_getTransactionByHash - Avalanche RPC Method

Returns the information about a transaction by transaction hash on Avalanche.

> **Why Avalanche?** Build on the fastest smart contract platform with sub-second finality and customizable L1 subnets with sub-second finality, Evergreen subnets for institutions, and partnerships with Franklin Templeton, VanEck, and Bergen County.

## When to Use This Method

`eth_getTransactionByHash` is essential for enterprise developers, RWA tokenizers, and teams building custom blockchain networks:

- **Track pending and confirmed transaction status**: Monitor the full lifecycle of a transaction from submission through finalization on Avalanche
- **Verify transaction parameters**: Confirm the value, gas, and input data match your intent for institutional RWA tokenization ($18B+ transfer volume), gaming subnets, and enterprise blockchains
- **Wallet transaction history display**: Show detailed transaction records with sender, receiver, value, and status for end users
- **Debug failed transactions**: Inspect raw transaction data to diagnose reverted calls and unexpected behavior on the fastest smart contract platform with sub-second finality and customizable L1 subnets

## Request Parameters

- `transactionHash` (`DATA, required`): 32-byte transaction hash

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionByHash",
  "params": ["0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4"],
  "id": 1
}
```

## Response Fields

- `hash` (`DATA, required`): Transaction hash
- `from` (`DATA, required`): Sender address
- `to` (`DATA, required`): Recipient address
- `value` (`QUANTITY, required`): Value in wei
- `gas` (`QUANTITY, required`): Gas provided
- `gasPrice` (`QUANTITY, required`): Gas price in wei
- `input` (`DATA, required`): Transaction input data
- `nonce` (`QUANTITY, required`): Sender's nonce
- `blockHash` (`DATA, required`): Block hash (null if pending)
- `blockNumber` (`QUANTITY, required`): Block number (null if pending)

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "hash": "<value>",
    "from": "<value>",
    "to": "<value>",
    "value": "0x1",
    "gas": "0x1",
    "gasPrice": "0x1",
    "input": "<value>",
    "nonce": "0x1",
    "blockHash": "<value>",
    "blockNumber": "0x1"
  }
}
```

## Common Use Cases

### 1. Wait for Transaction Confirmation with Polling

Poll `eth_getTransactionByHash` until the transaction's `blockNumber` becomes non-null, indicating it has been mined on Avalanche. This is the standard pattern for tracking transaction finality.

```javascript
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc');

async function waitForConfirmation(txHash, interval = 2000) {
  while (true) {
    const tx = await provider.getTransaction(txHash);

    if (tx && tx.blockNumber) {
      console.log(`Transaction confirmed in block #${tx.blockNumber}`);
      return tx;
    }

    console.log('Transaction pending, waiting...');
    await new Promise(r => setTimeout(r, interval));
  }
}

waitForConfirmation('0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4');
```

### 2. Display Transaction Details in a Wallet UI

Fetch and format transaction data for display in a wallet or explorer on Avalanche. Extract the key fields: sender, recipient, value, gas, and confirmation status.

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc'))

def get_transaction_details(tx_hash):
    tx = w3.eth.get_transaction(tx_hash)

    if not tx:
        return {'status': 'not found'}

    return {
        'hash': tx['hash'].hex(),
        'from': tx['from'],
        'to': tx['to'],
        'value_ether': w3.from_wei(tx['value'], 'ether'),
        'gas': tx['gas'],
        'gas_price_gwei': w3.from_wei(tx['gasPrice'], 'gwei'),
        'block': tx.get('blockNumber'),
        'confirmed': tx.get('blockNumber') is not None,
    }

details = get_transaction_details('0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4')
for key, value in details.items():
    print(f'{key}: {value}')
```

### 3. Decode Transaction Input Data for Contract Interaction Analysis

When a transaction's `input` field contains encoded function calls, decode it using a contract ABI to understand what action was performed on the fastest smart contract platform with sub-second finality and customizable L1 subnets.

```go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, _ := ethclient.Dial("https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc")

    txHash := common.HexToHash("0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4")
    tx, isPending, _ := client.TransactionByHash(context.Background(), txHash)

    fmt.Printf("Pending: %v\n", isPending)
    fmt.Printf("From: %s\n", tx.From().Hex())
    fmt.Printf("Value: %s wei\n", tx.Value().String())
    fmt.Printf("Gas limit: %d\n", tx.Gas())

    if len(tx.Data()) > 0 {
        // First 4 bytes are the function selector
        selector := tx.Data()[:4]
        fmt.Printf("Function selector: 0x%x\n", selector)
        fmt.Printf("Input data length: %d bytes\n", len(tx.Data()))
    }
}
```

## Best Practices

- **Check if `blockNumber` is null to detect pending transactions**: A null `blockNumber` indicates the transaction has been submitted but not yet mined; use this to drive polling or loading states in your UI
- **For mined transactions, cross-reference with receipt for confirmation count**: Once a block number is available, use `eth_getTransactionReceipt` to get the final status, gas used, and emitted logs
- **Cache confirmed transaction data indefinitely**: Transaction data is immutable once mined; cache it permanently to avoid redundant RPC calls for historical lookups
- **Use `eth_getTransactionReceipt` for post-confirmation data**: After a transaction is confirmed, call `eth_getTransactionReceipt` to get gas used, logs, status code, and effective gas price

## Code Examples

cURL
JavaScript
Python
Go

```bash
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_getTransactionByHash",
    "params": ["0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4"],
    "id": 1
  }'
```

```javascript
import { JsonRpcProvider, formatEther } from 'ethers';

const provider = new JsonRpcProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc');

const txHash = '0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4';
const tx = await provider.getTransaction(txHash);

if (tx) {
  console.log('From:', tx.from);
  console.log('To:', tx.to);
  console.log('Value:', formatEther(tx.value));
  console.log('Block:', tx.blockNumber);
}
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc'))

tx_hash = '0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4'
tx = w3.eth.get_transaction(tx_hash)

if tx:
    print(f'From: {tx["from"]}')
    print(f'To: {tx["to"]}')
    print(f'Value: {w3.from_wei(tx["value"], "ether")}')
    print(f'Block: {tx["blockNumber"]}')
```

```go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc")
    if err != nil {
        log.Fatal(err)
    }

    txHash := common.HexToHash("0xfe055919188f8e2360bead9ecd97ffa782c610730e9084c6533f799bafafa7e4")
    tx, isPending, err := client.TransactionByHash(context.Background(), txHash)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Pending: %v\n", isPending)
    fmt.Printf("Value: %s\n", tx.Value().String())
}
```

## Related Methods

- [`eth_getTransactionReceipt`](https://www.dwellir.com/docs/avalanche/eth_getTransactionReceipt) - Get transaction receipt
- [`eth_sendRawTransaction`](https://www.dwellir.com/docs/avalanche/eth_sendRawTransaction) - Send transaction
