Skip to main content
FunC contracts depend on the stdlib.fc file, which contains asm functions closely tied to TVM instructions. Tolk provides a standard library that gradually evolved from FunC’s stdlib. Therefore, many functions from stdlib.fc can be mapped to Tolk. But since Tolk is much more flexible as a language, most of the functions turned into methods.

Functions vs methods

Tolk supports declaring methods (see syntax) — even for primitives. That’s why lots of FunC’s global-scope functions are now methods: cell.hash(), tuple.size(), etc.
@pure
fun cell.hash(self): uint256
    asm "HASHCU"
In FunC, x.f() works equally to f(x). For instance, someTuple.tuple_size() and tuple_size(someTuple).In Tolk, someTuple.size() is the only correct notation.

List of renamed and removed functions

For load_xxx, store_xxx, and skip_xxx — use automatic serialization. Methods slice.loadXXX, builder.storeXXX, and slice.skipXXX still exist for manual cell parsing, but their use is not recommended. For idict_xxx, udict_xxx, and dict_xxx — use native maps. Old-fashioned dictionaries still exist in a file @stdlib/tvm-dicts, but their use is not recommended. Other functions are listed below.
  • some were renamed to clean, descriptive names
  • some became methods and are called via dot
  • some were removed, because they are rarely used in practice
  • some were removed, because they can be expressed syntactically
    • pair(a, b) => [a, b]
    • fourth(t) => dot-access t.3
    • etc.
FunC nameTolk name
empty_tuplecreateEmptyTuple
t~tpush(v)t.push(v)
first(t) or t.first()t.first()
at(t,i) or t.at(i)t.get(i) or dot-access t.{i}
touch(v)v.stackMoveToTop()
impure_touch(deleted)
single(deleted)
unsingle(deleted)
pair(deleted)
unpair(deleted)
triple(deleted)
untriple(deleted)
tuple4(deleted)
untuple4(deleted)
second(deleted)
third(deleted)
fourth(deleted)
pair_first(deleted)
pair_second(deleted)
triple_first(deleted)
triple_second(deleted)
triple_third(deleted)
minmaxminMax
nowblockchain.now
my_addresscontract.getAddress
get_balance + pair_firstcontract.getOriginalBalance
cur_ltblockchain.logicalTime
block_ltblockchain.currentBlockLogicalTime
cell_hash(c)c.hash()
slice_hash(s)s.hash()
string_hash(s)s.bitsHash()
check_signatureisSignatureValid
check_data_signatureisSliceSignatureValid
compute_data_size(c)c.calculateSizeStrict()
slice_compute_data_size(s)s.calculateSizeStrict()
compute_data_size?(c)c.calculateSize()
slice_compute_data_size?(s)s.calculateSize()
~dumpdebug.print
~strdumpdebug.printString
dump_stackdebug.dumpStack
get_datacontract.getData
set_datacontract.setData
get_c3getTvmRegisterC3
set_c3setTvmRegisterC3
blesstransformSliceToContinuation
accept_messageacceptExternalMessage
set_gas_limitsetGasLimit
buy_gas(deleted)
commitcommitContractDataAndActions
divmoddivMod
moddivmodDiv
muldivmulDivFloor
muldivrmulDivRound
muldivcmulDivCeil
muldivmodmulDivMod
begin_parsebeginParse
end_parse(s)s.assertEnd()
first_bits(s)s.getFirstBits()
skip_last_bits(s)s.removeLastBits()
slice_last(s)s.getLastBits()
cell_depth(c)c.depth()
slice_refs(s)s.remainingRefsCount()
slice_bits(s)s.remainingBitsCount()
slice_bits_refs(s)s.remainingBitsAndRefsCount()
slice_empty?(s)s.isEmpty()
slice_data_empty?(s)s.isEndOfBits()
slice_refs_empty?(s)s.isEndOfRefs()
slice_depth(s)s.depth()
equal_slice_bits(a,b)a.bitsEqual(b)
builder_refs(b)b.refsCount()
builder_bits(b)b.bitsCount()
builder_depth(b)b.depth()
begin_cellbeginCell
end_cellendCell
parse_addr(deleted)
parse_std_addruse address type
parse_var_addr(deleted)
config_paramblockchain.configParam
raw_reservereserveToncoinsOnBalance
raw_reserve_extrareserveExtraCurrenciesOnBalance
send_raw_messageuse createMessage
set_codecontract.setCodePostponed
randomrandom.uint256
randrandom.range
get_seedrandom.getSeed
set_seedrandom.setSeed
randomizerandom.initializeBy
randomize_ltrandom.initialize
dumpdebug.print
strdumpdebug.printString
dump_stkdebug.dumpStack
empty_listcreateEmptyList
conslistPrepend
unconslistSplit
list_nextlistNext
carlistGetHead
cdrlistGetTail
new_dictcreateEmptyMap
dict_empty?(d)m.isEmpty
pfxdict_get?prefixDictGet
pfxdict_set?prefixDictSet
pfxdict_delete?prefixDictDelete
Lisp-style lists require an explicit import (an IDE inserts it automatically):
import "@stdlib/lisp-lists"

Mutating functions

In FunC, x~method mutates, whereas x.method returns a copy. In Tolk, methods are called via dot. A method may (or may not) mutate the object.
FunCTolk
int n = cs~load_uint(32);var n = cs.loadUint(32);
var (cs2, n) = cs.load_uint(32);var cs2 = cs; var n = cs2.loadUint(32);
  • If cs~load_uint(…) was used, cs.loadUint(…) behaves identically.
  • If cs.load_uint(…) was used to obtain a copy, a different approach is required. Read about mutability.

Added functions

Tolk provides much more capabilities out of the box. See Tolk stdlib. The standard library is split into multiple files. Functions from common.tolk are always available (most of FunC’s analogues are, actually), but those from other files require an explicit import.
import "@stdlib/gas-payments"

// now `calculateGasFee()` and other symbols are visible