Skip to main content
FunC is the first high-level language for TON smart contracts. Legacy FunC codebases exist, but the compiler is no longer maintained. Tolk is the primary and only actively supported language in the TON ecosystem.

Migrating from FunC to Tolk

  1. Review the list of differences.
  2. See the Tolk contract examples page.
  3. Use the FunC-to-Tolk converter to migrate existing projects.

Gas benchmarks

The tolk-bench repository compares FunC and Tolk across several TEP contracts. See the Tolk contract examples page for selected cases. Across all measured metrics, Tolk reduces gas consumption by 30–50% compared to FunC. This reduction is primarily due to differences in language design.

Common characteristics

  • Both languages compile to Fift assembler.
  • Both languages run on TVM after compilation to bitcode.
  • Both languages are supported by IDE plugins.
  • Both languages are available in Blueprint and other client-side tooling.
  • Both support command-line usage.

Key differences

The differences between Tolk and FunC are primarily in language design rather than syntax.

Basic syntax

  • FunC resembles C, the name stands for “functional C”.
  • Tolk resembles TypeScript, Rust, and Kotlin.

Structures

  • FunC uses unnamed tensors such as (int, slice, int, int).
  • Tolk uses named structures with the same runtime efficiency.

Automatic serialization

  • FunC requires manual bit-level serialization using builders and slices.
  • Tolk derives serialization from struct using toCell and fromCell.
All integer types such as int8, uint64, and coins are TVM integers.

Lazy loading

  • FunC requires manual control over preloads and skips for optimization.
  • Tolk uses the lazy keyword to load only accessed fields.

Boolean type

  • FunC represents only integers: -1 for true, 0 for false; ifnot.
  • Tolk provides a bool type and logical operators &&, ||, and !.

Address type

  • FunC represents only slices; bits comparison and parsing.
  • Tolk provides a address type with methods and the == operator.

Null safety

  • FunC allows any variable to hold null, which may lead to runtime errors.
  • Tolk provides nullable types T?, null safety, and smart casts.

Type system features

  • FunC provides several types that expose TVM primitives.
  • Tolk provides a type system, including unions, generics, and enums.

Methods for all types

  • FunC provides functions in the global scope only.
  • Tolk provides both functions and methods, applicable to structures and primitives.

No impure keyword

  • In FunC, if impure is omitted, a function call may be dropped.
  • In Tolk, user function calls are not removed by the compiler.

No ~ tilde methods

  • FunC distinguishes between x~f() and x.f().
  • Tolk uses a dot . syntax for method calls.

Native maps over TVM dictionaries

  • FunC uses dictionaries, for example m~idict_set_builder(1,32,begin_cell().store_uint(10,32)).
  • Tolk provides native maps, for example m.set(1, 10).

Message handling

  • FunC defines () recv_internal(4 params) and parses a message cell.
  • Tolk provides onInternalMessage(in) and use in.senderAddress, etc.

Message routing

  • FunC routes incoming messages using if-else checks on the opcode, for example if (op == OP_TRANSFER).
  • Tolk routes messages using union types and pattern matching.

Empty messages handling

  • FunC checks for empty message bodies using if (slice_empty?(...)) at the beginning of recv_internal().
  • Tolk handles empty or unknown messages using else in a lazy matching.

Message composition

  • FunC requires manual bit-level message construction, for example store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1).
  • Tolk provides createMessage, which automatically chooses between inline body and body reference.

Deployment and StateInit

  • FunC requires manual packing of contract code and data according to TL-B.
  • Tolk uses createMessage to attach StateInit and compute the destination automatically.

Identifier syntax

  • FunC allows arbitrary symbols in identifiers, for example var 2+2 = ....
  • Tolk allows only alphanumeric identifiers, for example 2+2 is 4.

Automatic inlining of small functions

  • In FunC, prefer larger functions for reduced gas consumption.
  • In Tolk, the compiler auto-inlines functions without additional gas cost.
Is reduced to return 2 in assembler:
In FunC, inline modifier operates at the Fift level and may introduce extra stack permutations. In Tolk, inlining is performed at the compiler level and is combined with constant folding.

Merging consecutive builder.storeUint

  • FunC manually combines constant stores into b.storeUint(0x18,6).
  • Tolk merges b.storeUint(...).storeUint(...) if constant.
Translated to:

Standard library redesigned

There are differences between standard libraries. For example, functions from stdlib.fc started having descriptive names: Many global-scope functions became methods for primitives: String postfixes like "..."c became compile-time methods on strings:

Assembler functions

Although Tolk is a high-level language, it exposes low-level capabilities. Code may still be written in a FunC-style with manual builders and slices, and TVM instructions are supported.