> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ton.org/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.ton.org/feedback

```json
{
  "path": "/tvm/tools/ton-decompiler",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# TON Decompiler

[TON Decompiler](https://github.com/tact-lang/ton-opcode) is an utility for converting [BoC](/foundations/serialization/boc) of the contract into a [Fift](/languages/fift/overview)-like pseudocode.

Decompiled code cannot match match the original source. At the very least, variable names and high-level structure is removed during compilation. Variables and methods will get some generated names, for example, `?fun_ref_12345678`.

The resulting pseudocode might not compile back to the same BoC either.

## CLI usage

Install Tact language tool suite.

```bash theme={"theme":{"light":"github-light-default","dark":"dark-plus"},"languages":{"custom":["/resources/grammars/tolk.tmLanguage.json","/resources/grammars/tlb.tmLanguage.json","/resources/grammars/fift.tmLanguage.json","/resources/grammars/tasm.tmLanguage.json","/resources/grammars/func.tmLanguage.json"]}}
npm install -g @tact-lang/compiler
```

Then run it on a BoC file:

```bash theme={"theme":{"light":"github-light-default","dark":"dark-plus"},"languages":{"custom":["/resources/grammars/tolk.tmLanguage.json","/resources/grammars/tlb.tmLanguage.json","/resources/grammars/fift.tmLanguage.json","/resources/grammars/tasm.tmLanguage.json","/resources/grammars/func.tmLanguage.json"]}}
unboc example.boc
```

## API usage

Add it to the project

```bash theme={"theme":{"light":"github-light-default","dark":"dark-plus"},"languages":{"custom":["/resources/grammars/tolk.tmLanguage.json","/resources/grammars/tlb.tmLanguage.json","/resources/grammars/fift.tmLanguage.json","/resources/grammars/tasm.tmLanguage.json","/resources/grammars/func.tmLanguage.json"]}}
npm install @tact-lang/ton-decompiler
```

Then call a disassembler to decompile it, and a writer to put the result back into Fift-like pseudocode.

```ts theme={"theme":{"light":"github-light-default","dark":"dark-plus"},"languages":{"custom":["/resources/grammars/tolk.tmLanguage.json","/resources/grammars/tlb.tmLanguage.json","/resources/grammars/fift.tmLanguage.json","/resources/grammars/tasm.tmLanguage.json","/resources/grammars/func.tmLanguage.json"]}}
import { Cell } from "@ton/core";
import { disassembleRoot } from "./decompiler/disasm";
import { AssemblyWriter } from "./printer/assembly-writer";

const cell: Cell = ...; // your TVM contract bytecode
const program = disassembleRoot(cell);
const writer = new AssemblyWriter();
const code = writer.write(program);
console.log(code);
```
