Send message
Sending a message is the most frequent action that a smart contract performs during the action phase. It can get into the out action list by:
- The
SENDRAWMSGinstruction. - The
SENDMSGinstruction. - The
POPCTRinstruction.
The sending message action consists of:
- an 8-bit bitmask
modespecifying the way of sending; - a cell containing the message to send, which is serialized as
MessageRelaxedtype.
Message normalization
During the process of sending, the original message is normalized. In the final message that is sent to the destination address, the following changes are applied to the fields of the CommonMsgInfoRelaxed type:
ihr_disabledis set totrue;bouncedis set tofalse;fwd_feeis set to actual forward fee dedicated to the validators of the destination address shard;srcaddress is set to address of the sender smart contract;created_atis set to the current Unix timestamp;created_ltis set to the logical time of that action.
As a result, when composing a message cell, it is acceptable to:
- fill the
ihr_disabled,bounced,fwd_fee,created_at, andcreated_ltfields with any values; - fill the
srcfield withaddr_none.
If the message cell does not fit into the maximum allowed size (1023 bits) after the normalization, the process is repeated with different ways to pack it:
- with
initpacked in a separate cell, referred from the root cell; - with
initandbodypacked in separate cells.
If after the second attempt the message is still too large, the exception is thrown in the action phase. This can lead to rejecting the whole action phase, sending a bounce message, or skipping this action. The exact behavior depends on the mode bitmask of the action.
Serialization
action_send_msg#0ec3c86d mode:(## 8)
out_msg:^(MessageRelaxed Any) = OutAction;
out_list_node$_ prev:^Cell action:OutAction = OutListNode;
message$_ {X:Type} info:CommonMsgInfoRelaxed
init:(Maybe (Either StateInit ^StateInit))
body:(Either X ^X) = MessageRelaxed X;
int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool
src:MsgAddress dest:MsgAddressInt
value:CurrencyCollection extra_flags:(VarUInteger 16) fwd_fee:Grams
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;
ext_out_msg_info$11 src:MsgAddress dest:MsgAddressExt
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed; Last updated on