A Tolk file that defines a contract may start with aDocumentation Index
Fetch the complete documentation index at: https://docs.ton.org/llms.txt
Use this file to discover all available pages before exploring further.
contract declaration. This is a directive for tooling: it tells the compiler that the file is a contract and lists the public shapes that describe it.
The compiler uses this information to emit a machine-readable ABI — out.abi.json next to the produced out.fif — and to generate TypeScript wrappers, source maps, and other artifacts that the Acton toolchain consumes.
What the contract declaration affects
By convention, the file’s name matches the contract’s name (preferably PascalCase): JettonMinter.tolk, JettonWallet.tolk. Adding the declaration:
- lists the contract’s public interface in one place;
- enables ABI export and TypeScript wrappers;
- changes how imports propagate entrypoints (see below);
- requires all
get funand message entrypoints to live in the same file.
Entrypoints must be in the same file
Whencontract is present, all entrypoints (get fun, onInternalMessage, onExternalMessage) declarations must exist in the same file. They cannot be imported from another file — the compiler reports an error if you try.
Imports do not pollute entrypoints
When fileFoo.tolk declares contract Foo, then import "Foo" exposes its types, functions, and methods, but not its onInternalMessage and get fun. Those belong to Foo only.
This enables two patterns:
- Tests and scripts as standalone files. Import a contract and add your own
get funfor tests — no conflicts. - Multi-contract projects. A jetton minter can
import "JettonWallet"to reuse its types (WalletStorage, messages) without colliding ononInternalMessageor get methods.
Properties of contract
Most properties either describe the contract for explorers and clients, or expose information the compiler can not infer from imperative code (such as which messages are accepted). All properties are optional except those required for ABI fidelity in your case.
incomingMessages and storage cannot be inferred from source — Tolk treats MyStorage as a regular struct and lazy ... fromSlice as one of many ways to dispatch a body. The compiler asks you to declare them explicitly to make ABI honest and stable.
Contract ABI export
Invoked from the command line:out.abi.json next to out.fif. The ABI contains:
- contract metadata (name, author, version, description);
- incoming and outgoing internal messages, external messages, emitted events;
- storage shape (and storage at deployment, if any);
- get methods with parameters and return types;
- exceptions the contract may throw;
- user-defined declarations (structs, aliases, enums) and the unique types they reference;
- compiler name and version.
Doc comments
Place/// doc comments above declarations to enrich ABI with descriptions. They are then surfaced as comments in TypeScript wrappers, IDE hover, explorer UIs, and so on.
/// comments are treated as documentation. Regular // comments inside code are ignored.
Client-side type override
Sometimes the on-chain field is intentionally low-level (to save gas), but client tools should see a richer shape. Use the@abi.clientType annotation to expose a different type to ABI:
RemainingBitsAndRefs, but ABI advertises the richer union to clients.
Describing existing FunC contracts
To generate TypeScript wrappers (or any ABI-driven artifact) for an existing FunC contract, describe its interface in Tolk rather than hand-writing JSON. A skeleton with the contract declaration, type stubs, and an emptyonInternalMessage is enough for the compiler to emit a complete ABI.