> For the complete documentation index, see [llms.txt](https://docs.megaeth.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.megaeth.com/mega-evme/tracing/overview.md). Agents can also search and read this documentation through its [MCP server](https://docs.megaeth.com/~gitbook/mcp).

# Overview

Record step-by-step EVM execution with opcode, call, and pre-state tracers.

`mega-evme` can record detailed execution traces during EVM runs. Traces are useful for debugging reverts, analyzing gas consumption, and understanding call flow.

## Enabling Tracing

Add `--trace` to `run`, `tx`, or a single-transaction `replay` to enable tracing:

```bash
mega-evme run 0x60016000526001601ff3 --trace
```

By default, this uses the [opcode tracer](https://docs.megaeth.com/mega-evme/tracing/opcode-tracer.md). Use `--tracer` to pick a different tracer.

## Tracers

| Tracer                                                                     | `--tracer` value                | Description                                                            |
| -------------------------------------------------------------------------- | ------------------------------- | ---------------------------------------------------------------------- |
| [Opcode](https://docs.megaeth.com/mega-evme/tracing/opcode-tracer.md)      | `opcode` (default)              | Step-by-step opcode execution log with gas, stack, memory, and storage |
| [Call](https://docs.megaeth.com/mega-evme/tracing/call-tracer.md)          | `call`                          | Nested call tree showing CALL/CREATE hierarchy, gas, and return data   |
| [Pre-State](https://docs.megaeth.com/mega-evme/tracing/prestate-tracer.md) | `pre-state` (alias: `prestate`) | Account state accessed during execution, with optional diff mode       |

## Common Options

These flags apply to all tracers:

| Flag                    | Default  | Description                                         |
| ----------------------- | -------- | --------------------------------------------------- |
| `--trace`               | `false`  | Enable tracing                                      |
| `--trace.output <PATH>` | stdout   | Write trace output to a file instead of the console |
| `--tracer <TRACER>`     | `opcode` | Select which tracer to use                          |

## Output

Trace output is JSON. When `--trace.output` is not set, the trace is printed to stdout after the execution result. When `--trace.output` is set, the trace is written to the specified file and only the execution result appears on stdout.

```bash
# Trace to file
mega-evme run 0x60016000526001601ff3 \
  --trace --tracer opcode \
  --trace.output trace.json

# Trace to stdout (default)
mega-evme run 0x60016000526001601ff3 --trace
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.megaeth.com/mega-evme/tracing/overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
