Importing files
Error codes are commonly placed in a separate file, for exampleerrors.tolk:
parse.tolk, the file must be imported explicitly:
Name uniqueness
All top-level symbols must have unique names.- There is no
export const ...orexport fun ...declarations needed. - All constants, functions, and other top-level declarations are visible by default.
- No module‑private symbols exist.
fun log() in multiple files causes a duplicate declaration error when both files are imported.
Techniques to avoid name collisions:
- Use long, descriptive names for top-level symbols, especially in multi‑contract projects.
- Good:
ReturnExcessesBack,WalletStorage. - Bad:
Excesses,Storage.
- Good:
- Group integer constants to enums.
- Prefer methods to global-scope functions.
Repeated symbols across contracts
When developing multiple contracts, each contract has its own file and compilation target. Place acontract declaration in every entrypoint file:
onInternalMessage, onExternalMessage, and get fun belong to a specific contract. When a file declares contract, importing it exposes its types and functions but not these entrypoints — so ContractB can reuse ContractA’s storage and messages without any naming conflicts on onInternalMessage or get methods.
In addition, when contract is present, all entrypoints must live in the same file as the contract declaration; importing a file that declares a get fun is not allowed.
In a multi-contract project, each contract file typically contains only:
- its
contractdeclaration, - its entrypoints,
- and contract-specific logic.
import.
Import path mappings
Apart from relative paths, theimport statement can accept @-aliases:
paths in tsconfig.json. Unlike paths, Tolk does not use file masks: each alias is specified independently.
Specify mappings at compiler invocation: