# debug_traceTransaction - Plasma RPC Method

Traces a transaction execution on Plasma by transaction hash.

This method requires an archive node. It is not available on full nodes.

## When to Use This Method

- **Analyze transaction execution step-by-step** - Trace every opcode and internal call in a completed transaction for stablecoin transfers, payment apps, and wallets that need 1 second confirmation
- **Debug failed transactions** - Pinpoint the exact opcode and call depth where a transaction reverted on Plasma
- **Examine internal call traces** - Follow the full call tree including delegate calls and contract creations
- **Gas usage profiling** - Measure gas consumption per opcode to identify optimization opportunities

## Best Practices

- Requires archive node access; not available on standard full nodes
- Traces can be very large for complex transactions with many internal calls
- Use tracer options like `onlyTopCall` or `callTracer` to limit output size
- Store traces off-chain for analysis rather than querying repeatedly

## Request Parameters

- `txHash` (`DATA, required`): 32-byte transaction hash
- `tracerConfig` (`Object, optional`): Tracer configuration

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "debug_traceTransaction",
  "params": ["0xb7db21f5fcc47ea4f33c75deebf128eb8aaecaece720d3503e8752ec29df3e0f", {"tracer": "callTracer"}],
  "id": 1
}
```

## Response Fields

- `type` (`string, required`): Call type (CALL, DELEGATECALL, STATICCALL, CREATE, CREATE2)
- `from` (`string, required`): Sender address
- `to` (`string, required`): Receiver address
- `gas` (`string, required`): Gas provided for the call (hex)
- `gasUsed` (`string, required`): Gas consumed by the call (hex)
- `input` (`string, required`): Call data (hex)
- `output` (`string, required`): Return data (hex), present on success
- `value` (`string, required`): Value transferred in wei (hex)
- `error` (`string, required`): Revert reason, present on failure
- `calls` (`array, required`): Nested internal calls

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "type": "CALL",
    "from": "0xabc...",
    "to": "0xdef...",
    "gas": "0x13880",
    "gasUsed": "0x5208",
    "input": "0x",
    "output": "0x",
    "value": "0x0"
  }
}
```

## Tracer Options

- `{}` - Default opcode tracer (verbose)
- `{ tracer: "callTracer" }` - Call tree tracer
- `{ tracer: "prestateTracer" }` - Pre-state tracer

## Code Examples

cURL
JavaScript
Python

```bash
curl -X POST https://api-plasma-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "debug_traceTransaction",
    "params": ["0xb7db21f5fcc47ea4f33c75deebf128eb8aaecaece720d3503e8752ec29df3e0f", {"tracer": "callTracer"}],
    "id": 1
  }'
```

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

const provider = new JsonRpcProvider('https://api-plasma-mainnet.n.dwellir.com/YOUR_API_KEY');

const txHash = '0xb7db21f5fcc47ea4f33c75deebf128eb8aaecaece720d3503e8752ec29df3e0f';

// Call tracer - shows internal calls
const callTrace = await provider.send('debug_traceTransaction', [
  txHash,
  { tracer: 'callTracer' }
]);
console.log('Type:', callTrace.type);
console.log('From:', callTrace.from);
console.log('To:', callTrace.to);
console.log('Gas used:', parseInt(callTrace.gasUsed, 16));

// Prestate tracer - shows state before execution
const prestateTrace = await provider.send('debug_traceTransaction', [
  txHash,
  { tracer: 'prestateTracer' }
]);
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-plasma-mainnet.n.dwellir.com/YOUR_API_KEY'))

tx_hash = '0xb7db21f5fcc47ea4f33c75deebf128eb8aaecaece720d3503e8752ec29df3e0f'

# Call tracer
trace = w3.provider.make_request('debug_traceTransaction', [
    tx_hash,
    {'tracer': 'callTracer'}
])
print(f'Trace type: {trace["result"]["type"]}')
print(f'Gas used: {int(trace["result"]["gasUsed"], 16)}')
```

## Related Methods

- [`debug_traceCall`](https://www.dwellir.com/docs/plasma/debug_traceCall) - Trace without executing
- [`debug_traceBlockByNumber`](https://www.dwellir.com/docs/plasma/debug_traceBlockByNumber) - Trace entire block
