Reference
Common

Common

List of the most commonly used built-in global static functions.

Contextual

now

fun now(): Int

Returns the current Unix time (opens in a new tab).

Usage example:

let timeOffset: Int = now() + 1000; // thousand seconds from now()

myBalance

fun myBalance(): Int;

Returns the nanoToncoin balance of the smart contract as it was at the start of the compute phase (opens in a new tab) of the current transaction.

Usage example:

let iNeedADolla: Int = myBalance();
⚠️

Beware, that all message sending functions of Tact can change the actual contract's balance, but they won't update the value returned by this function.

myAddress

fun myAddress(): Address;

Returns the address of the current smart contract as an Address.

Usage example:

let meMyselfAndI: Address = myAddress();

sender

fun sender(): Address;

Returns the Address of the sender of the current message.

Usage example:

receive() {
    let whoSentMeMessage: Address = sender();
}
⚠️

Behavior is undefined for getter functions, as they cannot have a sender nor they can send messages.

💡

In order to reduce gas usage, prefer using this function over calling context().sender when you only need to know the sender of the message.

context

fun context(): Context;

Returns Context Struct, that consists of:

FieldTypeDescription
bouncedBoolBounced (opens in a new tab) flag of the incoming message.
senderAddressInternal address of the sender on the TON blockchain.
valueIntAmount of nanoToncoins in a message.
rawSliceThe remainder of the message as a Slice. It follows internal message layout (opens in a new tab) of TON starting from the destination Address (dest:MsgAddressInt in TL-B notation (opens in a new tab)).

Usage example:

let ctx: Context = context();
require(ctx.value != 68 + 1, "Invalid amount of nanoToncoins, bye!");
💡

Note, that if you only need to know who sent the message, use the sender() function, as it's less gas-consuming.

Addressing

newAddress

fun newAddress(chain: Int, hash: Int): Address;

Creates a new Address based on the chain id (opens in a new tab) and the SHA-256 encoded hash value (opens in a new tab).

This function tries to resolve constant values in compile-time whenever possible.

Usage example:

let oldTonFoundationAddr: Address =
    newAddress(0, 0x83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8);
    //         ↑  ------------------------------------------------------------------
    //         |  ↑
    //         |  sha-256 hash of contract's init package (StateInit)
    //         chain id: 0 is a workchain, -1 is a masterchain
⚠️

This method throws an error with exit code 136 if chain is invalid or with exit code 137 if chain points to the masterchain (1-1) without masterchain support enabled.

contractAddress

fun contractAddress(s: StateInit): Address;

Computes smart contract's Address in a workchain 00 based on its StateInit.

Usage example:

let foundMeSome: Address = contractAddress(initOf SomeContract());

contractAddressExt

fun contractAddressExt(chain: Int, code: Cell, data: Cell): Address;

Computes smart contract's Address based on the chain id, contract's code and contract's initial state data. Use initOf expression to obtain initial code and initial data of a given contract.

Usage example:

let initPkg: StateInit = initOf SomeContract();
let hereBeDragons: Address = contractAddressExt(0, initPkg.code, initPkg.data);
⚠️

This method throws an error with exit code 136 if chain is invalid or with exit code 137 if chain points to the masterchain (1-1) without masterchain support enabled.

💡

For this function to work, the compiler option debug has to be set to true for the current project in the configuration file.
Read more about debugging on the dedicated page: Debugging.

Communication

send

fun send(params: SendParameters);

Queues the message to be sent using a SendParameters Struct.

Usage example:

send(SendParameters{
    to: sender(),    // back to the sender,
    value: ton("1"), // with 1 Toncoin (1_000_000_000 nanoToncoin),
                     // and no message body
});

emit

fun emit(body: Cell);

Queues the message body to be sent to the outer world with the purpose of logging and analyzing it later off-chain. The message does not have a recipient and is gas-efficient compared to using any other message sending functions of Tact.

Usage example:

emit("Catch me if you can, Mr. Holmes".asComment()); // asComment() converts a String to a Cell
💡

To analyze emit() calls, one has to look at external messages produced by the contract.

Read more: Logging via emit().