# Decompiled code of a contract

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

A contract's code reconstructed as readable Solidity-like pseudocode, from the
bytecode on chain — so it works the same for contracts that never published
their code. The default answer is a table of contents of the functions, with
their names where a known signature has the selector; one function's body, or
all the bodies a page at a time, are a parameter away.

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

| 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 |
| `selector` | query | string, optional | one function's body: `0x` + 8 hex characters, or `fallback` / `receive`. Not with `bodies` or `cursor` |
| `bodies` | query | boolean, optional | `true` — the first page of bodies, in table-of-contents order |
| `cursor` | query | string, optional | `nextCursor` of the previous page — of bodies, or of the table of contents. Opaque, and valid only for the same address, `target` and `block` |

**Access** — an [API key](/api/authentication) on the **Intelligence** plan or higher ([plans](/api/authentication#plans)). Not sold over [x402](/api/x402) yet. As a tool for AI agents: `get_contract_decompilation` 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.

## Read the disclaimer

Every answer carries `disclaimer`, and it applies to every byte of the view:

> Best-effort reconstruction from public bytecode. Names are inferred from
> signature databases and may be wrong. Confirm any behaviour against on-chain
> state before relying on it.

The view is a reading aid, not the contract's original code. Variable names are
invented, and a function name is the best match for its 4-byte selector — the
same match the [selectors method](/api/contract-selectors) serves, with the
same `decodeStatus` and `candidateCount`. `lowConfidence` flags a function, or
the whole view, whose reconstruction is uncertain.

## Which code is shown

By default (`target=auto`) the answer is about the code that **runs** at the
address at the block: for a proxy, its implementation; for a beacon proxy, the
beacon's implementation; for a minimal proxy, its target; for an account with
an EIP-7702 delegation, the delegate's code. It follows one hop only.
`target.resolvedVia` says how the code was reached, and `target.codeAddress`
whose code it is. `target=self` shows the address's own code — a proxy's own
dispatcher.

The USDC address in the example below is a proxy: `resolvedVia: slot` and the
implementation's address in `codeAddress`.

## A code not analysed yet

A code is analysed once, on its first request; after that, anyone can read the
view without limit. A request for a code that is not analysed yet starts the
analysis and answers `503` with `reason: decompilation_pending` and a
`Retry-After` header — ask again after it, usually within a minute.

Each account starts a limited number of analyses per day, set by its plan,
and only a few at a time. Over the limit, the answer is `429 quota_exceeded`,
with `used`, `limit` and `retryAfterSeconds`; a code that is already analysed
is still served.

Over [MCP](/api/mcp-server), the same wait is a tool error
`decompilation_pending` with `retryAfterSeconds`: call the tool again after it.

When a newer analysis release exists and this code's view under it is not
computed yet, the earlier view is served with `releaseIsCurrent: false`.

## Three shapes of the answer

* **Table of contents** (default) — `functions[]`, one entry per function.
  It is paged by size (about 512 KiB of entries a page, one entry always
  given): while `hasMore` is `true`, pass `nextCursor` back as `cursor`.
* **One body** — `?selector=0x70a08231` answers the same envelope with `body`
  in place of `functions`. `hasBody` in the table of contents says whether a
  selector has one.
* **Bodies, a page at a time** — `?bodies=true` answers the first page in
  `bodies[]` and `nextCursor`; pass it back as `cursor` until it is absent.

`functionCount` — entries of the table of contents — and `hasMore` are on
every shape.

A body larger than 512 KiB as written comes without `text`:
`textState: withheld_for_size` and `textLength` (its length in bytes, UTF-8)
stand in its place. A page of bodies counts each body as written.

## Response

`200 application/json`, the USDC proxy, the table of contents cut to two of
its 55 functions:

```json
{
  "data": {
    "chainId": 1,
    "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "block": 26389912,
    "target": {
      "mode": "auto",
      "resolvedVia": "slot",
      "codeAddress": "0x43506849d7c04f9138d1a2050bbf3a0c054402dd",
      "codeHash": "0xcdfb7d322961af3acae7a8f7ee8b69c205b36f576cc5b077f170c7eb8ecbe3ea"
    },
    "analysis": {
      "codeHash": "0xcdfb7d322961af3acae7a8f7ee8b69c205b36f576cc5b077f170c7eb8ecbe3ea",
      "release": "rev:44a0daa70ae5",
      "computedAt": "2026-10-29T15:26:18Z"
    },
    "releaseIsCurrent": true,
    "disclaimer": "Best-effort reconstruction from public bytecode. Names are inferred from signature databases and may be wrong. Confirm any behaviour against on-chain state before relying on it.",
    "status": "done",
    "language": "solidity",
    "lowConfidence": false,
    "functionsDone": 55,
    "functionsTotal": 55,
    "functionCount": 55,
    "functions": [
      {
        "kind": "public",
        "selector": "0x70a08231",
        "name": "balanceOf",
        "signature": "balanceOf(address)",
        "decodeStatus": "ambiguous",
        "candidateCount": 2,
        "status": "done",
        "mutability": "view",
        "arguments": [{ "type": "address" }],
        "lowConfidence": false,
        "hasBody": true
      },
      {
        "kind": "public",
        "selector": "0xa9059cbb",
        "name": "transfer",
        "signature": "transfer(address,uint256)",
        "decodeStatus": "ambiguous",
        "candidateCount": 4,
        "status": "done",
        "mutability": "nonpayable",
        "arguments": [{ "type": "address" }, { "type": "uint256" }],
        "lowConfidence": false,
        "hasBody": true
      }
    ],
    "hasMore": false
  },
  "meta": {
    "chain": "ethereum",
    "timestamp": 1794384198609,
    "cached": false,
    "asOfBlock": 26389912,
    "docs": "https://docs.tracefast.xyz/api/contract-decompilation"
  }
}
```

The same address with `?selector=0x70a08231` carries, in place of `functions`:

```text
"body": {
  "selector": "0x70a08231",
  "kind": "public",
  "text": "    function balanceOf(address arg0) public view { // compiler ABI checks: pc 2546\n        return abi.encode(0x7fff…ffff & map_0x9[address(arg0)]);\n    }\n"
}
```

The `pc` numbers in a body are byte offsets in the code — the same offsets the
[disassembly](/api/contract-disassembly) lists.

### `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 and how it was reached — see below |
| `analysis` | `codeHash` of the analysed code, `release` — the analysis release that made the view, `rev:` + 12 hex (opaque: compare it, never parse it), `computedAt` — RFC 3339 UTC |
| `releaseIsCurrent` | `false` when an earlier release's view is served while the current one is computed |
| `disclaimer` | read it before relying on the view |
| `status` | `done`, `partial`, `unsupported` or `failed`. For a day after an attempt that could not finish: `timeout_wall`, `timeout_cpu` or `failed_infra`, then it is retried. With no view behind the status, `functions` is empty and `functionCount` is `0` |
| `unsupportedReason` | with `unsupported`: `eip7702_designator` (the code is only a delegation pointer — ask with `target=auto`) or `no_functions` |
| `language` | `solidity`, `vyper` or `unknown` |
| `lowConfidence` | the reconstruction as a whole is uncertain |
| `functionsDone`, `functionsTotal` | functions whose analysis finished, of all found |
| `functionCount` | entries of the table of contents, on every shape |
| `functions[]` | the table of contents — the default shape |
| `body` | with `selector`: that function's body |
| `bodies[]` | with `bodies=true` or `cursor`: a page of bodies, in table-of-contents order |
| `hasMore` | `true` when the answer is a page and more follows — of the table of contents or of bodies |
| `nextCursor` | pass as `cursor` for the next page — of the table of contents on a contents answer, of bodies on a bodies answer; absent on the last page |
| `outputLimited` | present (`true`) only when the view was cut to its size limit |

### `target`

| Field | Meaning |
|---|---|
| `mode` | `auto` or `self`, as asked |
| `resolvedVia` | how the code was reached at the block: `own` — the address's own code; `slot` — a proxy's implementation slot; `beacon` — a beacon proxy's beacon; `beacon_unproven` — a beacon whose implementation is not proven at the block; `eip1167` — a minimal proxy's target; `delegate` — an EIP-7702 delegation |
| `codeAddress` | the address whose code this is |
| `codeHash` | hash of the code |
| `targetUnresolved` | present (`true`) only when `auto` found no proven code to follow and the address's own code is served instead |

### A table-of-contents entry

| Field | Meaning |
|---|---|
| `kind` | `public` — reached through a selector; `fallback` or `receive` |
| `selector` | the 4-byte selector; absent for `fallback` and `receive` |
| `name`, `signature` | present when a known signature has the selector and its text is served — see [text from the chain](/api/conventions#text-from-the-chain) |
| `nameState` | `withheld` — a known signature has the selector, but its text is not served: no `name` or `signature`, and it is still counted in `decodeStatus` and `candidateCount`. Absent otherwise |
| `decodeStatus`, `candidateCount` | how confident the name is — `partial`, `ambiguous`, `abi_missing` — and how many known signatures share the selector, as on [selectors](/api/contract-selectors) |
| `status` | how far this function's analysis got: `done`, `partial`, `timeout`, `failed` |
| `mutability` | where the code shows it, for example `view` or `payable` |
| `arguments[]` | one entry per argument; `type` where the code checks one |
| `lowConfidence` | this function's reconstruction is uncertain |
| `hasBody` | whether `?selector=` returns a body for it |
| `bodyOmitted` | present (`true`) only when the body was left out to keep the view within its size limit |

A body — in `body` or `bodies[]` — has `kind`, `selector` (absent for
`fallback` and `receive`) and `text`, the function as pseudocode with known
names filled in. A body larger than 524,288 bytes as written (each invisible
character counted as its `<U+XXXX>` marker) has no `text`; instead
`textState` is `withheld_for_size` and `textLength` gives the body's length
in bytes (UTF-8).

## Errors

| Status | `code` | When | `details` |
|---|---|---|---|
| 400 | `bad_request` | `reason: target_invalid`, `selector_invalid`, `bodies_invalid`, or `selector_with_cursor` — `selector` with `bodies` or `cursor` | `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 the selector is not a function of this code | — |
| 422 | `block_not_available` | `block` is past the covered history | `maxAvailableBlock` |
| 429 | `quota_exceeded` | `reason: decompile_in_flight_limit` or `decompile_daily_limit` — your account may not start another analysis now. Codes already analysed are still served | `used`, `limit`, `retryAfterSeconds`, and `Retry-After` |
| 503 | `service_unavailable` | `reason: decompilation_pending` — the view is being computed; ask again after `Retry-After` | `pendingSince`, `queueDepth`, `retryAfterSeconds` |
| 503 | `service_unavailable` | `reason: decompilation_backlog_too_large` or `decompiler_unavailable` — no view of this code is stored and none can be started right now; retry later | `retryAfterSeconds` |

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

* [Disassembly of a contract](/api/contract-disassembly) — the same code as instructions, with the offsets a body cites
* [Function selectors of a contract](/api/contract-selectors) — the names, without analysis
* [Calls per function of a contract](/api/contract-function-calls) — which of these functions are actually called
* [Implementations of a proxy contract](/api/contract-proxy) — the history behind `target=auto`
* [Contracts on the entity page](/explorer/entity/contracts) — the Code tab, the same view in the app
