Skip to main content
FunC includes a low-level standard library in the stdlib.fc file, containing asm functions closely tied to TVM instructions. Tolk provides a standard library based on FunC’s with three main differences.
  1. It is split into multiple files: common.tolk, tvm-dicts.tolk, and others. Functions from common.tolk are available, while functions from other files require an import:
  2. No separate download from GitHub; is required; the library is included in the Tolk distribution.
  3. Tolk has functions and methods which are called using the dot operator. Many global FunC functions became methods of builders, slices, and other types, and can no longer be called as functions.

Functions vs methods

In FunC, there are no methods. All functions are globally scoped. Any function can be called using the dot operator:
Calling b.end_cell() invokes the global function end_cell. Since all functions are global, there are no “short methods”:
Tolk separates functions and methods, as in most languages:
  1. Functions cannot be called with the dot operator; only methods can.
  2. Methods can have short names without conflicts.

Renamed functions

In the table below, if the Required import column is empty, the function is available without imports. Some functions were removed because they can be expressed syntactically or are rarely used in practice. The table follows the order in which functions appear in stdlib.fc.

Added functions

Some functions from FunC are missing in Tolk’s standard library, but it works well for everyday tasks. Tolk is evolving, and its standard library is continually updated over time. Check the tolk-stdlib/ folder in the source code. In addition to functions, some constants are added, such as SEND_MODE_* and RESERVE_MODE_*. All of these functions are wrappers over TVM assembler instructions. Missing functionality can be implemented by manually wrapping any TVM instruction.

Mutating functions

Many FunC functions that used the ~ tilde now mutate the object in Tolk rather than returning a copy.
  • If cs~load_uint(…) was used, use cs.loadUint(…) and everything works.
  • If cs.load_uint(…) was used to get a copy, a different approach is needed. Read about mutability.

How the embedded stdlib works

All standard library functions are available out of the box. Non-common functions require an import, but no external downloads are needed. Here’s how it works:
  1. The Tolk compiler locates the stdlib folder by searching predefined paths relative to an executable binary. For example, when the Tolk compiler is launched from a system-installed package, e.g., /usr/bin/tolk, the stdlib is located in /usr/share/ton/smartcont. For custom installations, the TOLK_STDLIB environment variable can be set. This is standard practice for compilers.
  2. The WASM wrapper tolk-js also includes the stdlib, so all stdlib functions are available out of the box when using tolk-js directly or through blueprint.
  3. JetBrains and VS Code IDE plugins automatically locate the stdlib to provide auto-completion. Blueprint installs tolk-js automatically, creating the node_modules/@ton/tolk-js/ folder in the project structure. It contains common.tolk, tvm-dicts.tolk, and other stdlib files.