Importing files
Error codes are commonly placed in a separate file, for exampleerrors.tolk:
parse.tolk, the file must be imported explicitly:
When selecting items from auto-completion, IDE inserts imports automatically. This works in both JetBrains-based and VSCode-based IDEs.
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, compilation target. Contract files do not import one another; therefore, the following declarations do not conflict across different contracts:onInternalMessageandonExternalMessage;get fun;- other contract entrypoints.
- its entrypoints,
- optionally, a union of allowed messages,
- and contract-specific logic.
SomeMessage outgoing for one contract and incoming for another. When one contract deploys another, both must share the storage struct.
As a guideline, group messages, errors, utils, etc. in shared files, and use only minimal declarations inside each contract.tolk.