In practice, contract code is split across multiple files. Projects with multiple contracts share a single codebase, including messages, storage layouts, and related logic. Symbols defined in one file can be used in another by importing that file. After an import, all its public symbols are available to the importing file.Documentation Index
Fetch the complete documentation index at: https://companyname-a7d5b98e-onchain-lib-edits.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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, 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.
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: