Skip to content

Compile-time

This page lists all the built-in global static functions, which are evaluated at the time of building the Tact project and cannot work with non-constant, run-time data. These functions are commonly referred to as “compile-time functions” or comptime functions for short.

address

fun address(s: String): Address;

A compile-time function that converts a String with an address into the Address type and embeds it into the contract.

Usage example:

contract Example {
// Persistent state variables
addr: Address =
address("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"); // works at compile-time!
}

cell

fun cell(bocBase64: String): Cell;

A compile-time function that embeds a base64-encoded BoC bocBase64 as a Cell into the contract.

Usage examples:

contract Example {
// Persistent state variables
stored: Cell =
// Init package for Wallet V3R1 as a base64-encoded BoC
cell("te6cckEBAQEAYgAAwP8AIN0gggFMl7qXMO1E0NcLH+Ck8mCDCNcYINMf0x/TH/gjE7vyY+1E0NMf0x/T/9FRMrryoVFEuvKiBPkBVBBV+RDyo/gAkyDXSpbTB9QC+wDo0QGkyMsfyx/L/8ntVD++buA="); // works at compile-time!
}

slice

Available since Tact 1.5

fun slice(bocBase64: String): Slice;

A compile-time function that embeds a base64-encoded BoC bocBase64 as a Slice into the contract.

Usage examples:

contract Example {
// Persistent state variables
stored: Slice =
// Works at compile-time!
slice("te6cckEBAQEADgAAGEhlbGxvIHdvcmxkIXgtxbw="); // Hello world!
}

rawSlice

Available since Tact 1.5

fun rawSlice(hex: String): Slice;

A compile-time function that converts hex String with hex-encoded and optionally bit-padded contents as a Slice into the contract.

Contents are bit-padded if there’s an underscore _ at the very end of String. The padding removes all the trailing zeros and the last 11 bit before them:

// Not bit-padded
rawSlice("4a").loadUint(8); // 74, or 1001010 in binary
// Bit-padded
rawSlice("4a_").loadUint(6); // 18, or 10010 in binary

Note, that this function is limited and only allows to specify up to 10231023 bits.

Usage example:

contract Example {
// Persistent state variables
stored: Slice =
rawSlice("000DEADBEEF000"); // CS{Cell{03f...430} bits: 588..644; refs: 1..1}
bitPadded: Slice =
rawSlice("000DEADBEEF000_"); // CS{Cell{03f...e14} bits: 36..79; refs: 0..0}
}

ascii

Available since Tact 1.5

fun ascii(str: String): Int;

A compile-time function that concatenates the hexadecimal values of the characters in str into one and embeds the resulting Int into the contract. Only works for strings that occupy up to 3232 bytes, which allows to represent up to 3232 ASCII codes or up to 88 44-byte Unicode code points.

Usage example:

contract Example {
// Persistent state variables
a: Int = ascii("a"); // 97 or 0x61, one byte in total
zap: Int = ascii("⚡"); // 14850721 or 0xE29AA1, 3 bytes in total
doubleZap: Int = ascii("⚡⚡"); // 249153768823457 or 0xE29AA1E29AA1, 6 bytes in total
}

crc32

Available since Tact 1.5

fun crc32(str: String): Int;

A compile-time function that computes a checksum using CRC-32 algorithm and embeds the resulting Int value into the contract.

Usage example:

contract Example {
// Persistent state variables
checksum: Int = crc32("000DEADBEEF000"); // 1821923098
}

ton

fun ton(value: String): Int;

A compile-time function that converts the given Toncoins value from a human-readable format String to the nanoToncoin Int format.

Usage example:

contract Example {
// Persistent state variables
one: Int = ton("1"); // one Toncoin, which is equivalent to 10^9 nanoToncoins
pointOne: Int = ton("0.1"); // 0.1 Toncoin, which is equivalent to 10^8 nanoToncoins
nano: Int = ton("0.000000001"); // 10^-9 Toncoins, which is equivalent to 1 nanoToncoin
// works at compile-time!
}