# Disassembly of a contract

[Open the contract's Code tab →](https://tracefast.xyz/entity/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2?tab=code)

A contract's code as EVM instructions, each with its byte offset (`pc`), in
order, a page at a time. These are the same offsets the
[decompiled view](/api/contract-decompilation) cites, so a line of pseudocode
can be found in the instructions.

```
GET https://tracefast.xyz/api/v1/chains/1/contracts/{address}/disassembly
```

| Parameter | In | Type | Notes |
|---|---|---|---|
| `address` | path | string | `0x`-prefixed, 40 hex characters, any case |
| `block` | query | integer, optional | the block to resolve the code at. Default: the latest covered block |
| `target` | query | string, optional | `auto` (default) — the code that runs at the address, one hop through a proxy; `self` — the address's own code |
| `limit` | query | integer, optional | instructions per page, 1..5000, default 1000 |
| `cursor` | query | string, optional | `nextCursor` of the previous page. Opaque, and valid only for the same address, `target` and `block` |

**Access** — an [API key](/api/authentication) on the **Enriched Data** plan or higher ([plans](/api/authentication#plans)). Not sold over [x402](/api/x402) yet. As a tool for AI agents: `get_contract_disassembly` on the [MCP server](/api/mcp-server). **Stable** — see [stability](/api/conventions#stability).

`chains/1` is a literal: other chain ids answer `404 chain_not_supported`. An
unknown query parameter is refused rather than ignored.

## How to read it

* **Which code.** As on the [decompiled view](/api/contract-decompilation#which-code-is-shown):
  `target=auto` follows one hop through a proxy, a beacon, a minimal proxy or
  an EIP-7702 delegation; `target.resolvedVia` says how, and `target.codeAddress`
  whose code it is.
* **The tail is data.** Compilers append metadata to the end of the code. Its
  bytes decode as instructions, but they never run. `metadata` names the range,
  and every instruction with a byte inside it carries `inMetadata: true`.
* **A byte that is not an opcode** is listed with `op: "?"`. A `PUSH` whose
  argument runs past the end of the code carries `truncated: true`, and `arg`
  holds the bytes that exist.
* **Pages.** Pass `nextCursor` back as `cursor` until it is absent.
  `instructionCount` is the whole code, every page together.

What each opcode does:
[ethereum.org — opcodes](https://ethereum.org/developers/docs/evm/opcodes).

## Response

`200 application/json`, WETH, `?limit=6`:

```json
{
  "data": {
    "chainId": 1,
    "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "block": 26389912,
    "target": {
      "mode": "auto",
      "resolvedVia": "own",
      "codeAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "codeHash": "0xd0a06b12ac47863b5c7be4185c2deaad1c61557033f56c7d4ea74429cbb25e23"
    },
    "codeSize": 3124,
    "instructionCount": 1577,
    "metadata": { "fromPc": 3081, "length": 43 },
    "instructions": [
      { "pc": 0, "op": "PUSH1", "arg": "0x60" },
      { "pc": 2, "op": "PUSH1", "arg": "0x40" },
      { "pc": 4, "op": "MSTORE" },
      { "pc": 5, "op": "PUSH1", "arg": "0x04" },
      { "pc": 7, "op": "CALLDATASIZE" },
      { "pc": 8, "op": "LT" }
    ],
    "nextCursor": "AVs5LCJkMGEwNmIxMmFjNDc4NjNiNWM3YmU0MTg1YzJkZWFhZDFjNjE1NTcwMzNmNTZjN2Q0ZWE3NDQyOWNiYjI1ZTIzIl2QPnvCqcU-9RI_fdWriIPE"
  },
  "meta": {
    "chain": "ethereum",
    "timestamp": 1794384199067,
    "cached": false,
    "asOfBlock": 26389912,
    "docs": "https://docs.tracefast.xyz/api/contract-disassembly"
  }
}
```

### `data`

| Field | Meaning |
|---|---|
| `chainId` | `1` — Ethereum mainnet |
| `address` | the address asked about, lowercase |
| `block` | the block the code was resolved at |
| `target` | which code this is — `mode`, `resolvedVia`, `codeAddress`, `codeHash`, and `targetUnresolved` when `auto` found nothing proven to follow; see the [decompiled view](/api/contract-decompilation#target) |
| `codeSize` | bytes of code |
| `instructionCount` | instructions in the whole code, every page together |
| `metadata` | the compiler's metadata at the end of the code: `fromPc` — offset of its first byte, `length` — in bytes. Absent when the code has none |
| `instructions[]` | the page's instructions, in `pc` order |
| `nextCursor` | pass as `cursor` for the next page; absent on the last page |

### An instruction

| Field | Meaning |
|---|---|
| `pc` | byte offset of the instruction in the code |
| `op` | the mnemonic, for example `PUSH1` or `SSTORE`; `?` for a byte that is not an opcode |
| `arg` | the `PUSH` argument, `0x`-prefixed; absent for every other instruction |
| `inMetadata` | present (`true`) only when a byte of the instruction lies inside the compiler's metadata |
| `truncated` | present (`true`) only for a `PUSH` whose argument runs past the end of the code |

## Errors

| Status | `code` | When | `details` |
|---|---|---|---|
| 400 | `bad_request` | `reason: target_invalid`, or `limit` outside 1..5000 | `reason` |
| 400 | `invalid_cursor` | the cursor is not valid for this request — restart from the first page | — |
| 404 | `not_found` | no code is proven to run at the address at that block, or its bytes are not available | — |
| 422 | `block_not_available` | `block` is past the covered history | `maxAvailableBlock` |
| 422 | `code_too_large` | the code is larger than one read disassembles | `codeSize`, `maxCodeSize` |
| 503 | `service_unavailable` | the covered history cannot be read right now; retry shortly | — |

Malformed input, unknown parameters and the key check's `401`/`403`/`429` are the same for every method — see [conventions](/api/conventions#errors) and [API keys](/api/authentication#when-a-key-is-refused).

## Related pages

* [Decompiled code of a contract](/api/contract-decompilation) — the same code as pseudocode
* [Bytecode of a contract](/api/contract-bytecode) — the raw bytes
* [Function selectors of a contract](/api/contract-selectors) — the entry points found in the code
* [Contracts on the entity page](/explorer/entity/contracts) — the Code tab, the same listing in the app
