Message mode
As you might've noticed, messages are sent with the mode
param of a struct SendParameters
. It's 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.
Base modes
Mode value | Constant name | Description |
---|---|---|
- | Ordinary message (default). | |
SendRemainingValue | Carry all the remaining value of the inbound message in addition to the value initially indicated in the new message. | |
SendRemainingBalance | Carry all the remaining balance of the current smart contract instead of the value originally indicated in the message. |
Optional flags
Flag value | Constant name | Description |
---|---|---|
SendPayGasSeparately | Pay forward fees separately from the message value. | |
SendIgnoreErrors | Ignore any errors arising while processing this message during the action phase. | |
SendBounceIfActionFail | Bounce transaction in case of any errors during action phase. Has no effect if flag , SendIgnoreErrors is used. | |
SendDestroyIfZero | Current account must be destroyed if its resulting balance is zero (often used with mode , 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 adding them together as numbers.
For example, if you want to send a regular message and pay transfer fees separately, use the mode (default) and a flag to get mode
, which is equal to just use SendPayGasSeparately constant.
Alternatively, if you want to send the whole contract balance and destroy it immediately, use the mode and flag to get mode
, which is equal to SendRemainingBalance + SendDestroyIfZero.
Here's how the latter example would look in code:
let to: Address = ...;
let value: Int = ton("1");
send(SendParameters{
to: to,
value: value,
mode: SendRemainingBalance + SendDestroyIfZero,
body: "Hello, World!".asComment()
});
NOTE: There can be only one base mode, but number of optional flags may vary: you can use them all, none or just some.