---
title: Compile-time
description: "Various compile-time global functions from the Core library of Tact"
---

import { Badge } from '@astrojs/starlight/components';

This page lists all the built-in [global functions](/book/functions#fun-global) 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

```tact
fun address(s: String): Address;
```

A compile-time function that converts a [`String{:tact}`][p] containing an address into the [`Address{:tact}`][p] type and embeds it into the contract.

Usage example:

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

:::note

  The `address("...Address..."){:tact}` in Tact is equivalent to `"...Address..."a{:func}` in FunC.

:::

## cell

```tact
fun cell(bocBase64: String): Cell;
```

A compile-time function that embeds a base64-encoded [BoC][boc] `bocBase64` as a [`Cell{:tact}`][cell] into the contract.

Usage example:

```tact
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

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
fun slice(bocBase64: String): Slice;
```

A compile-time function that embeds a base64-encoded [BoC][boc] `bocBase64` as a [`Slice{:tact}`][slice] into the contract.

Usage example:

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

## rawSlice

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
fun rawSlice(hex: String): Slice;
```

A compile-time function that converts the `hex` [`String{:tact}`][p], containing hex-encoded and optionally bit-padded contents, into a [`Slice{:tact}`][slice] and embeds it into the contract.

Contents are bit-padded if there is an underscore `_` at the very end of the [`String{:tact}`][p]. Padding removes all trailing zeros and the last $1$ bit before them:

```tact
// 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 specifying up to $1023$ bits.

Usage example:

```tact
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}
}
```

:::note

  The `rawSlice("...Hex contents..."){:tact}` in Tact is equivalent to `"...Hex contents..."s{:func}` in FunC.

:::

## ascii

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
fun ascii(str: String): Int;
```

A compile-time function that concatenates the numerical values of the characters in the non-empty string `str` into one value of the [`Int{:tact}`][int] type. This function works only for strings occupying up to 32 bytes, allowing the representation of up to 32 [ASCII codes](https://en.wikipedia.org/wiki/ASCII#Control_code_chart) or up to 8 [Unicode code points](https://en.wikipedia.org/wiki/List_of_Unicode_characters) of 4 bytes each, so the resulting non-negative integer fits into 256 bits.

To understand how the `ascii` function works, consider the following pseudo-Tact example involving hexadecimal escape sequences:

```tact
ascii("NstK") == ascii("\x4e\x73\x74\x4b") == 0x4e73744b == 1316189259
```

Each ASCII character in the string `"NstK"` is represented by its hexadecimal escape sequence, which is then converted to the corresponding integer value by concatenating all the bytes.

The `ascii` builtin assumes the string is encoded in UTF-8. For example, the `⚡` character's UTF-8 encoding is `0xE2 0x9A 0xA1`, so `0xE2` will be the most significant byte.

The builtin can be used to create human-readable encodings for some actions or operations.

Usage example:

```tact
message(42) Action {
  action: Int as uint256;
}

contract Example {
    receive(msg: Action) {
        if (msg.action == ascii("start")) {
            // Do something
        } else if (msg.action == ascii("stop")) {
            // Do something else
        }
    }
}
```

:::note

  The `ascii("...String contents..."){:tact}` in Tact is almost equivalent to `"...String contents..."u{:func}` in FunC.
  But FunC does not support Unicode code point escapes or hexadecimal escape sequences.

:::

## crc32

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
fun crc32(str: String): Int;
```

A compile-time function that computes a checksum using the [CRC-32](https://en.wikipedia.org/wiki/Cyclic_redundancy_check) algorithm and embeds the resulting [`Int{:tact}`][int] value into the contract.

Usage example:

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

:::note

  The `crc32("...String contents..."){:tact}` in Tact is equivalent to `"...String contents..."c{:func}` in FunC.

:::

## ton

```tact
fun ton(value: String): Int;
```

A compile-time function that converts the given Toncoin `value` from a human-readable format [`String{:tact}`][p] to the [nanoToncoin](/book/integers#nanotoncoin) [`Int{:tact}`][int] format.

Usage example:

```tact
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!
}
```

[p]: /book/types#primitive-types
[bool]: /book/types#booleans
[int]: /book/integers
[cell]: /book/cells#cells
[slice]: /book/cells#slices

[boc]: /book/cells#cells-boc

[crc]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
