Import a file to access its symbols
For example, error codes are placed inerrors.tolk:
parse.tolk, an explicit import is required:
An IDE inserts imports automaticallyFortunately, when selecting items from auto‑completion, imports are inserted automatically.
It works in both JetBrains and VSCode-based IDEs.
All top‑level symbols must have unique names
Notice that noexport const ... or export fun ... declarations needed.
All constants, functions, etc. are visible.
No module‑private symbols exist.
It means that all symbols must have unique names.
Having fun log() in multiple files results in a “duplicate declaration” error if 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 (read an idiom)
Symbols that may be repeated across the project
When developing multiple contracts, each contract has its own file (compilation target). They do not import one another; therefore,onInternalMessageandonExternalMessageget fun- and other declarations in a contract file don’t conflict with each other
- its entrypoints,
- probably, a union with allowed messages,
- and little else; the remaining codebase is shared.
SomeMessage, outgoing for contract A, is incoming for contract B.
When deploying one contract from another, a storage struct must be known. And similar.
As a guideline, group messages / errors / utils / etc. in shared files,
and use only minimal declarations inside each contract.tolk.