> ## Documentation Index
> Fetch the complete documentation index at: https://seilabs-docs-evm-cookbook.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Debug Tracing Overview

> Comprehensive guide to debugging and tracing EVM transactions on Sei. Learn to analyze transaction execution, optimize gas usage, and troubleshoot smart contracts with real examples and end-to-end workflows.

## Requirements

The examples in this guide call the debug JSON-RPC endpoints directly with `curl`. You do not need an SDK or other libraries. To pretty-print the JSON responses, you can install [`jq`](https://jqlang.github.io/jq/):

```bash theme={null}
# macOS
brew install jq

# Debian/Ubuntu
sudo apt-get install jq
```

Debug tracing is your primary tool to understand how EVM transactions execute on Sei. With it, you can analyze transaction flow, optimize gas usage, debug smart contract interactions, and troubleshoot production issues.

## What you can trace

### Transaction execution

* Step-by-step opcode execution
* Contract call hierarchy
* Gas consumption breakdown
* State changes and storage access

### Contract interactions

* Cross-contract calls and returns
* Event emission analysis
* Precompile usage tracking
* External library calls

### Performance analysis

* Gas optimization opportunities
* Bottleneck identification
* Cache hit and miss patterns
* State access efficiency

### Security analysis

* Suspicious operation detection
* Reentrancy pattern analysis
* Access control verification
* Vulnerability scanning

## Available tracing methods

| Method | Purpose | Use case |
| - | - | - |
| `debug_traceTransaction` | Trace a specific transaction | Debugging failed transactions |
| `debug_traceBlockByNumber` | Trace an entire block | Block-level analysis |
| `debug_traceCall` | Simulate and trace | Testing before execution |
| `debug_traceStateAccess` | State access patterns | Performance optimization |
| `debug_traceTransactionProfile` | Trace plus timing/store-access profiling | Latency breakdown and DB-access analysis |

## Transaction analysis example

This example traces an ERC-20 transfer transaction:

<Tabs>
  <Tab title="Transaction Details">
    ```bash theme={null}
    # Real transaction on Sei Mainnet
    TRANSACTION_HASH="0x75b7ba10248e90db85b224eae587db1728520b6f72c795b9185064f444cee7c3"

    # Transaction details

    curl -X POST -H "Content-Type: application/json" \
     --data '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByHash",
    "params": ["'$TRANSACTION_HASH'"],
    "id": 1
    }' \
     https://evm-rpc.sei-apis.com

    ```

    **Response:**

    ```json theme={null}
    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "blockHash": "0xbc229fe41605ba2b46fcd7aa7ce328dc2f6da78385dfea84ca8dbef7b4325462",
        "blockNumber": "0x97aefcf",
        "from": "0x4cbee7ad42d33e9d3b41e8b6faca2f6f173c8a94",
        "gas": "0x66f24",
        "gasPrice": "0x565dd756",
        "maxFeePerGas": "0x565dd756",
        "maxPriorityFeePerGas": "0x5e679d6",
        "hash": "0x75b7ba10248e90db85b224eae587db1728520b6f72c795b9185064f444cee7c3",
        "input": "0x733214a3e5f551789f7ee58322679a2b141e64533098b8ba41d9e10cf8061a18a777d6ce00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a940000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000f6a756d7065722e65786368616e67650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783030303030303030303030303030303030303030303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004faaa00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001642646478b0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f1000000000000000000000000000000000000000000000000000000000004faaa000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000070023894085ef7ff0f0aedf52e2a2704928d1ec074f101ffff015cfa8db453c9904511c4ea9eb0bfc903e36b9f5f01fde9ce4e17b650efdca13d524f132876700d806f01e30fedd158a2e3b13e9badaeabafc5516e95e8c701ffff02001231deb6f5749ef6ce6943a275a1d3e7486f4eae0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "nonce": "0x4",
        "to": "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
        "transactionIndex": "0x14",
        "value": "0x0",
        "type": "0x2",
        "accessList": [],
        "chainId": "0x531",
        "v": "0x0",
        "r": "0x3a107aca9cd554a9171a65ea2e8ef56ebeca8cfdc17f4bbecfb0f86837ca90d6",
        "s": "0x426134cf65b701bc8d43162f78bcf787319ff17cc6293188bcbb30fd99feb60",
        "yParity": "0x0"
      }
    }
    ```
  </Tab>

  <Tab title="Basic Trace">
    ```bash theme={null}
    # Trace the transaction execution
    curl -X POST -H "Content-Type: application/json" \
      --data '{
        "jsonrpc": "2.0",
        "method": "debug_traceTransaction",
        "params": [
          "'$TRANSACTION_HASH'",
          {
            "tracer": "callTracer",
            "tracerConfig": {
              "withLog": true
            }
          }
        ],
        "id": 1
      }' \
      https://evm-rpc.sei-apis.com
    ```

    **Response:**

    ```json theme={null}
    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "from": "0x4cbee7ad42d33e9d3b41e8b6faca2f6f173c8a94",
        "gas": "0x66f24",
        "gasUsed": "0x40f98",
        "to": "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
        "input": "0x733214a3e5f551789f7ee58322679a2b141e64533098b8ba41d9e10cf8061a18a777d6ce00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a940000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000f6a756d7065722e65786368616e67650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783030303030303030303030303030303030303030303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004faaa00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001642646478b0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f1000000000000000000000000000000000000000000000000000000000004faaa000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000070023894085ef7ff0f0aedf52e2a2704928d1ec074f101ffff015cfa8db453c9904511c4ea9eb0bfc903e36b9f5f01fde9ce4e17b650efdca13d524f132876700d806f01e30fedd158a2e3b13e9badaeabafc5516e95e8c701ffff02001231deb6f5749ef6ce6943a275a1d3e7486f4eae0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "calls": [
          {
            "from": "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
            "gas": "0x5d03f",
            "gasUsed": "0x3b0cc",
            "to": "0x31a9b1835864706af10103b31ea2b79bdb995f5f",
            "input": "0x733214a3e5f551789f7ee58322679a2b141e64533098b8ba41d9e10cf8061a18a777d6ce00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a940000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000f6a756d7065722e65786368616e67650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783030303030303030303030303030303030303030303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f000000000000000000000000fde9ce4e17b650efdca13d524f132876700d806f0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004faaa00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001642646478b0000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f1000000000000000000000000000000000000000000000000000000000004faaa000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000dd26083bfc745570000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000070023894085ef7ff0f0aedf52e2a2704928d1ec074f101ffff015cfa8db453c9904511c4ea9eb0bfc903e36b9f5f01fde9ce4e17b650efdca13d524f132876700d806f01e30fedd158a2e3b13e9badaeabafc5516e95e8c701ffff02001231deb6f5749ef6ce6943a275a1d3e7486f4eae0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "calls": [
              {
                "from": "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
                "gas": "0x5aa48",
                "gasUsed": "0xa724",
                "to": "0x3894085ef7ff0f0aedf52e2a2704928d1ec074f1",
                "input": "0x23b872dd0000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a940000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae000000000000000000000000000000000000000000000000000000000004faaa",
                "output": "0x0000000000000000000000000000000000000000000000000000000000000001",
                "calls": [
                  {
                    "from": "0x3894085ef7ff0f0aedf52e2a2704928d1ec074f1",
                    "gas": "0x54283",
                    "gasUsed": "0x4ad6",
                    "to": "0x0000000000000000000000000000000000001001",
                    "input": "0x5c05961b0000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a940000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000004faaa00000000000000000000000000000000000000000000000000000000000000446962632f4341364642464146333939343734413036323633453130443043453541454242453135313839443644344232444439414445363130303745363845423944423000000000000000000000000000000000000000000000000000000000",
                    "output": "0x0000000000000000000000000000000000000000000000000000000000000001",
                    "value": "0x0",
                    "type": "CALL"
                  }
                ],
                "logs": [
                  {
                    "address": "0x3894085ef7ff0f0aedf52e2a2704928d1ec074f1",
                    "topics": [
                      "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                      "0x0000000000000000000000004cbee7ad42d33e9d3b41e8b6faca2f6f173c8a94",
                      "0x0000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae"
                    ],
                    "data": "0x000000000000000000000000000000000000000000000000000000000004faaa",
                    "position": "0x1"
                  }
                ],
                "value": "0x0",
                "type": "CALL"
              },
              ...
            ]
          }
        ]
      }
    }
    ```
  </Tab>

  <Tab title="Gas Analysis">
    ```bash theme={null}
    # Analyze gas usage patterns
    curl -X POST -H "Content-Type: application/json" \
      --data '{
        "jsonrpc": "2.0",
        "method": "debug_traceTransaction",
        "params": [
          "0x75b7ba10248e90db85b224eae587db1728520b6f72c795b9185064f444cee7c3",
          {
            "tracer": "{gasUsed: 0, operations: {}, step: function(log, db) { var op = log.op.toString(); var cost = log.getCost(); this.gasUsed += cost; if (!this.operations[op]) { this.operations[op] = { count: 0, totalGas: 0 }; } this.operations[op].count++; this.operations[op].totalGas += cost; }, fault: function(log, db) {}, result: function(ctx, db) { return { totalGas: this.gasUsed, operations: this.operations, efficiency: this.gasUsed / ctx.gasUsed }; }}"
          }
        ],
        "id": 1
      }' \
      https://evm-rpc.sei-apis.com
    ```

    **Response:**

    ```json theme={null}
    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "totalGas": 6346011,
        "operations": {
          "PUSH1": {
            "count": 1476,
            "totalGas": 4428
          },
          "MSTORE": {
            "count": 342,
            "totalGas": 1690
          },
          "CALLDATASIZE": {
            "count": 41,
            "totalGas": 82
          },
          "PUSH2": {
            "count": 1400,
            "totalGas": 4200
          },

          ...


          "STOP": {
            "count": 5,
            "totalGas": 0
          },
          "LOG2": {
            "count": 2,
            "totalGas": 5578
          },
          "LOG4": {
            "count": 1,
            "totalGas": 2899
          },
          "LOG1": {
            "count": 1,
            "totalGas": 2542
          }
        },
        "efficiency": 23.84499278564343
      }
    }
    ```
  </Tab>
</Tabs>

## Debugging failed transactions

Use these steps to analyze and fix transaction failures:

### Step 1: Identify the problem

```bash theme={null}
# Get transaction receipt
FAILED_TX="0xb2a6f4f7f37d8df728968126c05d1a8b0391003cf375ed5abb1b5e02fe66c717"

curl -X POST -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionReceipt",
    "params": ["'$FAILED_TX'"],
    "id": 1
  }' \
  https://evm-rpc.sei-apis.com
```

### Step 2: Trace the execution

```bash theme={null}
# Trace to see where it failed
curl -X POST -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "debug_traceTransaction",
    "params": [
      "'$FAILED_TX'",
      {
        "tracer": "callTracer",
        "tracerConfig": {
          "withLog": true
        }
      }
    ],
    "id": 1
  }' \
  https://evm-rpc.sei-apis.com
```

**Response:**

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "from": "0x2c80b1b0473bb765ef536d2526ec63195794d945",
    "gas": "0xc3500",
    "gasUsed": "0x2863d",
    "to": "0xd1efe48b71acd98db16fcb9e7152b086647ef544",
    "input": "0x414bf3890000000000000000000000003894085ef7ff0f0aedf52e2a2704928d1ec074f1000000000000000000000000e30fedd158a2e3b13e9badaeabafc5516e95e8c70000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000002c80b1b0473bb765ef536d2526ec63195794d94500000000000000000000000000000000000000000000000000000000688a24580000000000000000000000000000000000000000000000000000000031aba85500000000000000000000000000000000000000000000009556d1a971e567965b0000000000000000000000000000000000000000000000000000000000000000",
    "output": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000013546f6f206c6974746c6520726563656976656400000000000000000000000000",
    "error": "execution reverted",
    "revertReason": "Too little received",
    "calls": [
      ...
    ]
  }
}
```

### Step 3: Fix and test

```bash theme={null}
# Simulate the fix with debug_traceCall
curl -X POST \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "debug_traceCall",
    "params": [
      {
        "from": "0x2c80b1b0473bb765ef536d2526ec63195794d945",
        "to": "0xd1efe48b71acd98db16fcb9e7152b086647ef544",
        "gas": "0xc3500",
        "gasPrice": "0x2127ddd32",
        "value": "0x0"
      },
      "0x98a87cc",
      {
        "tracer": "callTracer",
        "tracerConfig": {
          "onlyTopCall": false,
          "withLog": true
        }
      }
    ],
    "id": 1
  }' \
  https://evm-rpc.sei-apis.com
```

## Common debugging scenarios

### Transaction reverted

**Problem**: The transaction failed with a revert.
**Solution**: Use `callTracer` to find the exact revert reason.

### Out of gas

**Problem**: The transaction ran out of gas.
**Solution**: Use the gas analysis tracer to optimize gas usage.

### Unexpected behavior

**Problem**: The transaction succeeded, but the result is wrong.
**Solution**: Use the opcode tracer for step-by-step analysis.

### Slow performance

**Problem**: The transaction uses too much gas.
**Solution**: Use the state access tracer to find inefficiencies.

## Quick reference

### Essential commands

```bash theme={null}
# Trace transaction
debug_traceTransaction(hash, {tracer: "callTracer"})

# Trace block
debug_traceBlockByNumber("latest", {tracer: "callTracer"})

# Simulate call
debug_traceCall(tx, "latest", {tracer: "callTracer"})

# State access
debug_traceStateAccess(hash)
```

### Common tracers

* **`callTracer`**: Contract call hierarchy
* **`opcodeTracer`**: Opcode-level execution
* **Custom JS**: Custom analysis logic

## Pre-baked trace cache

RPC nodes can optionally pre-compute and cache `debug_trace*` results in the background. The node then serves trace requests from a local on-disk cache instead of re-executing the block live on every call. You configure this opt-in feature through `[evm]` fields in `app.toml`. It is recommended for RPC nodes only.

When the feature is enabled, a background worker re-executes each committed block with the configured tracers. It stores the results in a Pebble database at `<home>/data/trace_db`. These methods serve results from this cache on a cache hit. Otherwise, they fall through to live re-execution:

* `debug_traceTransaction`
* `debug_traceBlockByNumber` and `debug_traceBlockByHash`

### When the cache is used

The node serves a request from the cache only when trace baking is enabled **and** the request uses a *bakeable* tracer configuration:

* The tracer is one of `callTracer`, `prestateTracer`, or `flatCallTracer`.
* The request does not include a custom `tracerConfig`. A per-call `tracerConfig` (for example, `{"withLog": true}`) is not part of the cache key. Any custom tracer config makes the request un-bakeable, so it falls through to live re-execution.

Requests that use the struct logger (no tracer), a JavaScript tracer, or any other named tracer always run live.

### Configuration

These `[evm]` fields in `app.toml` control trace baking:

| Field | Default | Description |
| - | - | - |
| `trace_bake_enabled` | `false` | Enables the background trace-baking worker that caches results at `<home>/data/trace_db`. RPC nodes only. |
| `trace_bake_workers` | `1` | Number of re-execution worker goroutines. |
| `trace_bake_queue_size` | `4096` | Bounds the in-flight height queue. When the queue is full, heights are dropped so that consensus never blocks. Dropped blocks fall through to live re-execution. |
| `trace_bake_tracers` | `["callTracer"]` | Which tracers to bake per block. Eligible values: `callTracer`, `prestateTracer`, `flatCallTracer`. |
| `trace_bake_window_blocks` | `0` | Rolling prune window: blocks older than `(latest - window)` are pruned. `0` disables pruning, so the cache grows without limit. |
| `trace_bake_use_snapshot` | `false` | Uses in-memory memiavl snapshots as the state backend for trace baking when the store backend supports snapshots. |
| `trace_bake_snapshot_window` | `64` | Number of recent memiavl snapshots to keep for trace baking. |

<Warning>Trace baking adds a persistent on-disk store at `<home>/data/trace_db` and increases disk usage. The node flushes the store's write-ahead log when it shuts down cleanly.</Warning>

## Removed legacy trace filters

<Note>The legacy `*ExcludeTraceFail` endpoints have been removed. For block tracing, use `debug_traceBlockByNumber` or `debug_traceBlockByHash`. For EVM receipts, use `eth_getTransactionReceipt`. There is no block or filter method to discover synthetic logs from Cosmos-originated transactions. If you already know a synthetic transaction hash, enable `sei_getTransactionReceipt` to get its receipt and logs.</Note>

## Next steps

1. **[JavaScript tracers](/evm/tracing/javascript-tracers)**: Custom analysis scripts
2. **[Troubleshooting](/evm/tracing/troubleshooting)**: Common issues and solutions

<Info>Start with `callTracer` for general debugging. Then use specialized tracers for specific analysis needs.</Info>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.