Skip to content

Message mode

As it was previously mentioned, messages sent via send() function utilize the mode param of the SendParameters structure. The mode is an Int value, which is combined from base modes and optional flags, which are also Int values.

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.

Note that there are other message-sending functions — they do not use the SendParameters Struct, but accept the mode as one of their parameters.

Base modes

Mode valueConstant nameDescription
00Since Tact 1.6 (not released yet) SendDefaultModeOrdinary message (default).
6464SendRemainingValueCarry all the remaining value of the inbound message in addition to the value initially indicated in the new message.
128128Use with caution SendRemainingBalanceCarry all the remaining balance of the current smart contract instead of the value originally indicated in the message.
10241024Since Tact 1.5 SendOnlyEstimateFeeDoesn’t send the message, only estimates the forward fees if the message-sending function computes those.

The base mode SendRemainingValue does not take previous actions into account, i.e. it doesn’t recalculate the remaining value of the incoming message based on previously sent messages or performed actions during action phase.

Unlike SendRemainingValue, the base mode SendRemainingBalance always calculates the current value of the contract balance, which can help solve problems with complex outbound message processing.

However, be very careful when using SendRemainingBalance, because it works with the balance of the whole contract and any mistake with it can lead to a total loss of funds.

Optional flags

Flag valueConstant nameDescription
+1+1SendPayGasSeparatelyPay forward fees separately from the message value.
+2+2SendIgnoreErrorsIgnore any errors arising while processing this message during the action phase.
+16+16SendBounceIfActionFailBounce transaction in case of any errors during action phase. Has no effect if flag +2+2, SendIgnoreErrors is used.
+32+32SendDestroyIfZeroCurrent account (contract) will be destroyed if its resulting balance is zero. This flag is often used with mode 128128, SendRemainingBalance.

Combining modes with flags

To make the Int value for mode field of SendParameters, you just have to combine base modes with optional flags by applying the bitwise OR operation.

For example, if you want to send a regular message and pay transfer fees separately, use the mode 00 (default) and a flag +1+1 to get mode =1= 1, which is equal to using SendPayGasSeparately constant.

Alternatively, if you want to send the whole contract balance and destroy it immediately, use the mode 128128 and flag +32+32 to get mode =160= 160, which is equal to SendRemainingBalance | SendDestroyIfZero.

Here’s how the latter example would look in code:

let to: Address = address("...");
let value: Int = ton("1");
send(SendParameters{
to: to,
value: value,
mode: SendRemainingBalance | SendDestroyIfZero,
body: "Hello, World!".asComment(),
});

Note that there can be only one base mode, but number of optional flags may vary: you can use them all, none or just some.

Functions with implicit mode

Some message-sending functions do not allow to set a mode by passing an argument. That’s because their internal logic requires specific fixed set of modes to be used instead: