> 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/call-tracer.md). Agents can also search and read this documentation through its [MCP server](https://docs.megaeth.com/~gitbook/mcp).

# Call Tracer

Capture the nested CALL/CREATE tree with gas usage, return data, and log events.

The call tracer records the nested tree of CALL, STATICCALL, DELEGATECALL, CALLCODE, and CREATE operations. It shows which contracts called which, with gas usage and return data at each level.

## Usage

```bash
mega-evme run 0x... --trace --tracer call
```

## Options

| Flag                         | Default | Description                                                |
| ---------------------------- | ------- | ---------------------------------------------------------- |
| `--trace.call.only-top-call` | `false` | Only trace the top-level call — omit nested internal calls |
| `--trace.call.with-log`      | `false` | Include LOG events in the call trace output                |

## Output Format

The call tracer emits a Geth-compatible nested JSON structure.

### Schema

Each call node contains:

| Field     | Type       | Description                                                                      |
| --------- | ---------- | -------------------------------------------------------------------------------- |
| `type`    | string     | Call type: `CALL`, `STATICCALL`, `DELEGATECALL`, `CALLCODE`, `CREATE`, `CREATE2` |
| `from`    | address    | Caller address                                                                   |
| `to`      | address    | Callee address                                                                   |
| `gas`     | hex number | Gas provided to the call                                                         |
| `gasUsed` | hex number | Gas consumed by the call                                                         |
| `input`   | hex bytes  | Calldata                                                                         |
| `output`  | hex bytes  | Return data (present on success)                                                 |
| `value`   | hex number | ETH value transferred (if any)                                                   |
| `error`   | string     | Revert reason (present on failure)                                               |
| `calls`   | array      | Nested child call nodes (recursive)                                              |
| `logs`    | array      | LOG events (only with `--trace.call.with-log`)                                   |

Each log entry (when `--trace.call.with-log` is set):

| Field      | Type       | Description                   |
| ---------- | ---------- | ----------------------------- |
| `address`  | address    | Contract that emitted the log |
| `topics`   | array      | Log topics as hex strings     |
| `data`     | hex bytes  | Log data                      |
| `position` | hex number | Position in the transaction   |

### Example Output

Running `WETH.name()` against MegaETH mainnet with `--tracer call` shows the nested call tree — WETH delegates to L1Block to resolve the chain name:

```json
{
  "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
  "gas": "0x97a960",
  "gasUsed": "0x1130f",
  "to": "0x4200000000000000000000000000000000000006",
  "input": "0x06fdde03",
  "output": "0x00000000000000000000000000000000000000000000000000...5772617070656420457468657200...",
  "calls": [
    {
      "from": "0x4200000000000000000000000000000000000006",
      "gas": "0x949600",
      "gasUsed": "0x15c4",
      "to": "0x4200000000000000000000000000000000000015",
      "input": "0xd8444715",
      "output": "0x00000000000000000000000000000000000000000000000000...4574686572...",
      "calls": [
        {
          "from": "0x4200000000000000000000000000000000000015",
          "gas": "0x918a50",
          "gasUsed": "0x247",
          "to": "0xc0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30015",
          "input": "0xd8444715",
          "output": "0x00000000000000000000000000000000000000000000000000...4574686572...",
          "value": "0x0",
          "type": "DELEGATECALL"
        }
      ],
      "type": "STATICCALL"
    }
  ],
  "value": "0x0",
  "type": "CALL"
}
```

With `--trace.call.with-log`, `WETH.deposit()` shows the emitted `Deposit` event:

```json
{
  "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
  "gas": "0x97a960",
  "gasUsed": "0x171a8",
  "to": "0x4200000000000000000000000000000000000006",
  "input": "0xd0e30db0",
  "logs": [
    {
      "address": "0x4200000000000000000000000000000000000006",
      "topics": [
        "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c",
        "0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"
      ],
      "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000",
      "position": "0x0"
    }
  ],
  "value": "0x38d7ea4c68000",
  "type": "CALL"
}
```

## Examples

Full call tree:

```bash
# Trace a WETH.balanceOf call against live mainnet state
mega-evme tx \
  --fork --rpc https://mainnet.megaeth.com/rpc \
  --sender.balance 1ether \
  --receiver 0x4200000000000000000000000000000000000006 \
  --input 0x70a08231000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266 \
  --trace --tracer call
```

Top-level call only (useful for simple gas analysis):

```bash
mega-evme tx \
  --receiver 0x4200000000000000000000000000000000000006 \
  --input 0x06fdde03 \
  --trace --tracer call \
  --trace.call.only-top-call
```

Include log events:

```bash
# WETH.deposit() emits a Deposit event — use --trace.call.with-log to capture it
mega-evme tx \
  --fork --rpc https://mainnet.megaeth.com/rpc \
  --sender.balance 1ether \
  --receiver 0x4200000000000000000000000000000000000006 \
  --input 0xd0e30db0 \
  --value 1000000000000000 \
  --trace --tracer call \
  --trace.call.with-log
```


---

# 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/call-tracer.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.
