Compile-time
This page lists all the built-in global static functions that are evaluated at the time of building the Tact project and cannot work with non-constant runtime 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
containing 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 example:
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.5fun slice(bocBase64: String): Slice;
A compile-time function that embeds a base64-encoded BoC bocBase64
as a Slice
into the contract.
Usage example:
contract Example { // Persistent state variables stored: Slice = // Works at compile-time! slice("te6cckEBAQEADgAAGEhlbGxvIHdvcmxkIXgtxbw="); // Hello world!}
rawSlice
Available since Tact 1.5fun rawSlice(hex: String): Slice;
A compile-time function that converts the hex
String
, containing hex-encoded and optionally bit-padded contents, into a Slice
and embeds it into the contract.
Contents are bit-padded if there is an underscore _
at the very end of the String
. Padding removes all trailing zeros and the last bit before them:
// Not bit-paddedrawSlice("4a").loadUint(8); // 74, or 1001010 in binary
// Bit-paddedrawSlice("4a_").loadUint(6); // 18, or 10010 in binary
Note that this function is limited and only allows specifying up to 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.5fun ascii(str: String): Int;
A compile-time function that concatenates the hexadecimal values of the characters in str
into one value and embeds the resulting Int
into the contract. This function works only for strings occupying up to bytes, allowing the representation of up to ASCII codes or up to Unicode code points of bytes each.
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.5fun crc32(str: String): Int;
A compile-time function that computes a checksum using the 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 Toncoin 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 Toncoin, which is equivalent to 1 nanoToncoin // Works at compile-time!}