Common
List of the most commonly used built-in global static functions.
Contextual
now
fun now(): Int
Returns the current Unix time.
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 of the current transaction.
Usage example:
let iNeedADolla: Int = myBalance();
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:
contract MeSee { receive() { let whoSentMeMessage: Address = sender(); }}
context
fun context(): Context;
Returns Context
Struct, that consists of:
Field | Type | Description |
---|---|---|
bounced | Bool | Bounced flag of the incoming message. |
sender | Address | Internal address of the sender on the TON blockchain. |
value | Int | Amount of nanoToncoins in a message. |
raw | Slice | The remainder of the message as a Slice . It follows internal message layout of TON starting from the destination Address (dest:MsgAddressInt in TL-B notation). |
Usage example:
let ctx: Context = context();require(ctx.value != 68 + 1, "Invalid amount of nanoToncoins, bye!");
Addressing
newAddress
fun newAddress(chain: Int, hash: Int): Address;
Creates a new Address
based on the chain
id and the SHA-256 encoded hash
value.
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
contractAddress
fun contractAddress(s: StateInit): Address;
Computes smart contract’s Address
in a workchain 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);
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