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:
    import "@stdlib/tvm-dicts"
    
    beginCell()          // always available
    createEmptyDict()    // available due to 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:
;; FunC
cell config_param(int x) asm "CONFIGOPTPARAM";

config_param(16);   ;; ok
16.config_param();  ;; also ok
Calling b.end_cell() invokes the global function end_cell. Since all functions are global, there are no “short methods”:
someTuple.tuple_size();
;; why not someTuple.size()? because it's a global function:
;; int tuple_size(tuple t)
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.
// FunC
someCell.cell_hash();     // or cell_hash(someCell)
someSlice.slice_hash();

// Tolk
someCell.hash();          // the only possible
someSlice.hash();

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.
FunC uses snake_case, for example, begin_cell, while Tolk methods use camelCase, for example, beginCell.
The table follows the order in which functions appear in stdlib.fc.
FunC nameTolk nameRequired import
empty_tuplecreateEmptyTuple
t~tpusht.push(v)
first(t) or t.first()t.first()
at(t,i) or t.at(i)t.get(i), t.0, etc.
touch(v)v.stackMoveToTop()TVM low-level
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()
c.compute_data_size?()c.calculateSize()
slice_compute_data_size?()s.calculateSize()
~dumpdebug.print
~strdumpdebug.printString
dump_stackdebug.dumpStack
get_datacontract.getData
set_datacontract.setData
get_c3getTvmRegisterC3TVM low-level
set_c3setTvmRegisterC3TVM low-level
blesstransformSliceToContinuationTVM low-level
accept_messageacceptExternalMessage
set_gas_limitsetGasLimit
buy_gas(deleted)
commitcommitContractDataAndActions
divmoddivMod
moddivmodDiv
muldivmulDivFloor
muldivrmulDivRound
muldivcmulDivCeil
muldivmodmulDivMod
begin_parsebeginParse
end_parse(s)s.assertEnd()
load_refloadRef
preload_refpreloadRef
load_intloadInt
load_uintloadUint
preload_intpreloadInt
preload_uintpreloadUint
load_bitsloadBits
preload_bitspreloadBits
load_gramsloadCoins
load_coinsloadCoins
skip_bitss.skipBits
first_bitsgetFirstBits
skip_last_bitsremoveLastBits
slice_lastgetLastBits
load_dictloadDict
preload_dictpreloadDict
skip_dictskipDict
load_maybe_refloadMaybeRef
preload_maybe_refpreloadMaybeRef
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
store_refstoreRef
store_uintstoreUint
store_intstoreInt
store_slicestoreSlice
store_gramsstoreCoins
store_coinsstoreCoins
store_dictstoreDict
store_maybe_refstoreMaybeRef
store_builderstoreBuilder
load_msg_addrloadAddress
parse_addr(deleted)
parse_std_addrparseStandardAddress
parse_var_addr(deleted)
config_paramblockchain.configParam
raw_reservereserveToncoinsOnBalance
raw_reserve_extrareserveExtraCurrenciesOnBalance
send_raw_messagesendRawMessage
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_listcreateEmptyListlisp-lists
conslistPrependlisp-lists
unconslistSplitlisp-lists
list_nextlistNextlisp-lists
carlistGetHeadlisp-lists
cdrlistGetTaillisp-lists
new_dictcreateEmptyMap
dict_empty?(d)m.isEmpty
pfxdict_get?prefixDictGetTVM dicts
pfxdict_set?prefixDictSetTVM dicts
pfxdict_delete?prefixDictDeleteTVM dicts
idict_set_refuse native maps
udict_set_refuse native maps
idict_get_refuse native maps
idict_get_ref?use native maps
udict_get_ref?use native maps
idict_set_get_refuse native maps
udict_set_get_refuse native maps
idict_delete?use native maps
udict_delete?use native maps
idict_get?use native maps
udict_get?use native maps
idict_delete_get?use native maps
udict_delete_get?use native maps
udict_setuse native maps
idict_setuse native maps
dict_setuse native maps
udict_add?use native maps
udict_replace?use native maps
idict_add?use native maps
idict_replace?use native maps
udict_set_builderuse native maps
idict_set_builderuse native maps
dict_set_builderuse native maps
udict_add_builder?use native maps
udict_replace_builder?use native maps
idict_add_builder?use native maps
idict_replace_builder?use native maps
udict_delete_get_minuse native maps
idict_delete_get_minuse native maps
dict_delete_get_minuse native maps
udict_delete_get_maxuse native maps
idict_delete_get_maxuse native maps
dict_delete_get_maxuse native maps
udict_get_min?use native maps
udict_get_max?use native maps
udict_get_min_ref?use native maps
udict_get_max_ref?use native maps
idict_get_min?use native maps
idict_get_max?use native maps
idict_get_min_ref?use native maps
idict_get_max_ref?use native maps
udict_get_next?use native maps
udict_get_nexteq?use native maps
udict_get_prev?use native maps
udict_get_preveq?use native maps
idict_get_next?use native maps
idict_get_nexteq?use native maps
idict_get_prev?use native maps
idict_get_preveq?use native maps
udict::delete_get_minuse native maps
idict::delete_get_minuse native maps
dict::delete_get_minuse native maps
udict::delete_get_maxuse native maps
idict::delete_get_maxuse native maps
dict::delete_get_maxuse native maps

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.
FunCTolk
int flags = cs~load_uint(32);var flags = cs.loadUint(32);
  • 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.