Advanced
Various niche, dangerous or unstable features which can produce unexpected results and are meant to be used by the more experienced users.
Context.readForwardFee
Extension function for the Context
.
Reads forward fee and returns it as Int
amount of nanoToncoins.
Usage example:
getConfigParam
Loads a configuration parameter of TON Blockchain by its id
number.
Usage examples:
acceptMessage
Agrees to buy some gas to finish the current transaction. This action is required to process external messages, which bring no value (hence no gas) with themselves.
Usage example:
commit
Commits the current state of registers c4
(“persistent data”) and c5
(“actions”), so that the current execution is considered “successful” with the saved values even if an exception in compute phase is thrown later.
Usage example:
nativePrepareRandom
Prepares a random number generator by using nativeRandomizeLt()
. Automatically called by randomInt()
and random()
functions.
Usage example:
nativeRandomize
Randomizes the pseudo-random number generator with the specified seed x
.
Usage example:
nativeRandomizeLt
Randomizes the random number generator with the current logical time.
Usage example:
nativeRandom
Generates and returns an -bit random number just like randomInt()
, but doesn’t initialize the random generator with nativePrepareRandom()
beforehand.
nativeRandomInterval
Generates and returns a -bit random number in the range from to max
similar to random()
, but doesn’t initialize the random generator with nativePrepareRandom()
beforehand.
nativeSendMessage
Queues the message to be sent by specifying the complete cell
and the message mode
.
nativeReserve
Calls native raw_reserve
function with specified amount and mode. The raw_reserve
is a function that creates an output action to reserve a specific amount of nanoToncoins from the remaining balance of the account.
It has the following signature in FunC:
The function takes two arguments:
amount
: The number of nanoToncoins to reserve.mode
: Determines the reservation behavior.
Function raw_reserve
is roughly equivalent to creating an outbound message carrying the specified amount
of nanoToncoins (or b
amount
nanoToncoins, where b
is the remaining balance) to oneself. This ensures that subsequent output actions cannot spend more money than the remainder.
It’s possible to use raw Int
values and manually provide them for the mode
, but for your convenience there’s a set of constants which you may use to construct the compound mode
with ease. Take a look at the following tables for more information on base modes and optional flags.
Base modes
The resulting mode
value can have the following base modes:
Mode value | Constant name | Description |
---|---|---|
ReserveExact | Reserves exactly the specified amount of nanoToncoins. | |
ReserveAllExcept | Reserves all, but the specified amount of nanoToncoins. | |
ReserveAtMost | Reserves at most the specified amount of nanoToncoins. |
Optional flags
Additionally, the resulting mode
can have the following optional flags added:
Flag value | Constant name | Description |
---|---|---|
ReserveAddOriginalBalance | Increases the amount by the original balance of the current account (before the compute phase), including all extra currencies. | |
ReserveInvertSign | Negates the amount value before performing the reservation. | |
ReserveBounceIfActionFail | Bounces the transaction if reservation fails. |
Combining modes with flags
To make the Int
value for mode
parameter, you just have to combine base modes with optional flags by applying the bitwise OR operation:
parseStdAddress
Available since Tact 1.5Converts a Slice
containing an address into the StdAddress
Struct and returns it. The StdAddress
is a built-in Struct that consists of:
Field | Type | Description |
---|---|---|
workchain | Int as int8 | Workchain ID of the address, usually (basechain) or (masterchain) |
address | Int as uint256 | Address in the specified workchain |
Attempts to pass a Slice
with layout different from the StdAddress
or to load more data than a given Slice
contains throw an exception with exit code 9: Cell underflow
.
Usage example:
parseVarAddress
Available since Tact 1.5Converts a Slice
containing an address of variable length into the VarAddress
Struct and returns it. The VarAddress
is a built-in Struct consisting of:
Field | Type | Description |
---|---|---|
workchain | Int as int32 | Workchain ID of the variable length address |
address | Slice | Address in the specified workchain |
Attempts to pass a Slice
with layout different from the VarAddress
or to load more data than a given Slice
contains throw an exception with exit code 9: Cell underflow
.
Usage example: