Type system overview
Tolk has the following types:
- numbers —
int,int32,uint64,coins, and others. - boolean —
trueandfalse. - address —
internal,external, andnone. - cells — containers with up to 1023 bits of data and up to 4 references to other cells, plus the cell manipulation primitives of TVM: builders and slices.
- structures — multiple fields grouped into one entity.
- generics — any struct can be generic
<T>. - enums — distinct types containing integer variants.
- nullable types —
nullsafety and safe casts. - union types — variables holding one of several possible values.
- strings — string values stored as snake-encoded cells.
- tensors — multiple values placed sequentially on the stack.
- arrays — dynamically sized containers backed by TVM tuples.
- maps — key-value dictionaries.
- callables — first-class functions.
- unknown — any value that is a single-slot TVM primitive.
voidandnever— both represent the absence of a value.
To give an existing type another name, use type aliases. An alias is assignable to and from its underlying type. Methods declared on the alias apply only to that alias.
Smart contracts run on a stack-based virtual machine, TVM, which imposes specific rules on how values are represented at runtime. For example, strings are stored as snake-encoded cells, because TVM has no native string support.
All on-chain data and communication rely entirely on cells, so the type system focuses on binary serialization and clear data relationships:
- Type checks and casts covers casting with the unsafe
asoperator. - TVM stack representation summarizes how types map to the TVM stack.
- Serialization describes how types serialize and relate to TL-B.