Skip to content

Commit 84e1b6d

Browse files
pixelplexvkokosh
andauthored
Added message modes cookbook (#724)
Co-authored-by: Vladislav Kokosh <v.kokosh@pixelplex.io>
1 parent b53a6c9 commit 84e1b6d

14 files changed

+187
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Message Modes Cookbook
2+
3+
Understanding the different modes and flags available for sending messages is important to ensure that your smart contracts behave correctly.
4+
While [Message-modes](/develop/smart-contracts/messages#message-modes) section provided detailed descriptions of these modes and flags, in this section we will illustrate their practical application with concrete examples.
5+
6+
:::info IMPORTANT
7+
The result of the error cases is described when the error occurred.
8+
:::
9+
10+
## 1. Send a regular message
11+
12+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin, we send a regular message with 20 Toncoin, the transaction fee is 3 Toncoin and will be deducted from the message.
13+
14+
![](/img/docs/message-modes-cookbook/send_regular_message.svg)
15+
16+
| Mode and Flags | Code |
17+
|:-|:-|
18+
| `mode` = 0, no `flag` | `send_raw_message(msg, 0)` |
19+
20+
## 2. Send a regular message, no bounce the message on error and ignore it
21+
22+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin, we send a regular message with 20 Toncoin, the transaction fee is 3 Toncoin and will be deducted from the message.
23+
In case of an error during transaction processing, the message will not bounce and will be ignored.
24+
25+
![](/img/docs/message-modes-cookbook/send_regular_message_and_ignore_errors.svg)
26+
27+
| Mode and Flags | Code |
28+
|:-|:-|
29+
| `mode` = 0, `flag` = 2 | `send_raw_message(msg, 2)` |
30+
31+
## 3. Send a regular message and bounce the message on error
32+
33+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin, we send a regular message with 20 Toncoin, the transaction fee is 3 Toncoin and will be deducted from the message,
34+
if an error occurs during action processing - bounce the message in addition to rolling back the transaction.
35+
36+
![](/img/docs/message-modes-cookbook/send_regular_message_and_bounce_if_error.svg)
37+
38+
| Mode and Flags | Code |
39+
|:-|:-|
40+
| `mode` = 0, `flag` = 16 | `send_raw_message(msg, 16)` |
41+
42+
## 4. Send a regular message with separate fees
43+
44+
We have 100 Toncoin on our smart contract balance, we receive an internal message with 50 Toncoin and send a regular message with 20 Toncoin, the total fee is 3 Toncoin and we pay the transfer fee separately (from the contract balance).
45+
46+
![](/img/docs/message-modes-cookbook/send_regular_and_pay_fees_separately.svg)
47+
48+
| Mode and Flags | Code |
49+
|:-|:-|
50+
| `mode` = 0, `flag` = 1 | `send_raw_message(msg, 1)` |
51+
52+
## 5. Send a regular message with separate fees and bounce the message on error
53+
54+
We have 100 Toncoin on our smart contract balance and we receive an internal message with 50 Toncoin and send a regular message with 20 Toncoin, the total fee is 3 Toncoin and we pay the transfer fee separately (from the contract balance),
55+
if an error occurs during action processing - bounce the message in addition to rolling back the transaction.
56+
57+
![](/img/docs/message-modes-cookbook/send_regular_message_pay_fee_separately_bounce_if_error.svg)
58+
59+
| Mode and Flags | Code |
60+
|:-|:-|
61+
| `mode` = 0, `flag` = 1 + 16 = 17 | `send_raw_message(msg, 17)` |
62+
63+
## 6. Carry remaining value with new message
64+
65+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we carry all the remaining value of the inbound message in addition to the value initially indicated in the new message,
66+
the transaction fee is 3 Toncoin and will be deducted from the message.
67+
68+
![](/img/docs/message-modes-cookbook/сarry_all_the_remaining_value.svg)
69+
70+
| Mode and Flags | Code |
71+
|:-|:-|
72+
| `mode` = 64, no `flag` | `send_raw_message(msg, 64)` |
73+
74+
## 7. Carry remaining value with new message with separate fees
75+
76+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we carry all the remaining value of the inbound message in addition to the value initially indicated in the new message,
77+
the transaction fee is 3 Toncoin and will be paid separately (from the smart contract balance).
78+
79+
![](/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_pay_fees_separately.svg)
80+
81+
| Mode and Flags | Code |
82+
|:-|:-|
83+
| `mode` = 64, `flag` = 1 | `send_raw_message(msg, 65)` |
84+
85+
## 8. Carry remaining value and bounce the message on error
86+
87+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we carry all the remaining value of the inbound message in addition to the value initially indicated in the new message,
88+
the transaction fee is 3 Toncoin and will be deducted from the message, if an error occurs during action processing - bounce the message in addition to rolling back the transaction.
89+
90+
![](/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_if_error_bounce.svg)
91+
92+
| Mode and Flags | Code |
93+
|:-|:-|
94+
| `mode` = 64, `flag` = 16 | `send_raw_message(msg, 80)` |
95+
96+
## 9. Carry remaining value with new message with separate fees and bounce the message on error
97+
98+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we send a message, we transfer the entire contract balance in addition to the original amount received, the transaction fee is 3 Toncoin and will be paid separately (from the smart contract balance),
99+
if an error occurs during action processing - bounce the message in addition to rolling back the transaction.
100+
101+
![](/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_pay_fees_separately_and_if_error_bounce.svg)
102+
103+
| Mode and Flags | Code |
104+
|:-|:-|
105+
| `mode` = 64, `flag` = 16 + 1 | `send_raw_message(msg, 81)` |
106+
107+
## 10. Send all received tokens together with the contract balance
108+
109+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we send a message, we transfer the entire contract balance in addition to the original amount received,
110+
the transaction fee is 3 Toncoin and will be deducted from the message.
111+
112+
![](/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance.svg)
113+
114+
| Mode and Flags | Code |
115+
|:-|:-|
116+
| `mode` = 128, no `flag` | `send_raw_message(msg, 128)` |
117+
118+
## 11. Send all received tokens together with the contract balance and bounce the message on error
119+
120+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin we send a message, we transfer the entire contract balance in addition to the original amount received, the transaction fee is 3 Toncoin and will be deducted from the message,
121+
if there was an error in processing the action - bounce the message in addition to rolling back the transaction.
122+
123+
![](/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance_and_if_error_bounce.svg)
124+
125+
| Mode and Flags | Code |
126+
|:-|:-|
127+
| `mode` = 128, `flag` = 16 | `send_raw_message(msg, 144)` |
128+
129+
## 12. Send all received tokens together with the contract balance and destroy smart-contract
130+
131+
We currently have 100 Toncoin in the balance of our smart contract. After receiving an internal message with 50 Toncoin, we send a message to transfer the entire contract balance in addition to the original amount received and destroy the contract,
132+
the transaction fee is 3 Toncoin and will be deducted from the message.
133+
134+
![](/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance_and_destroy_sc.svg)
135+
136+
| Mode and Flags | Code |
137+
|:-|:-|
138+
| `mode` = 128, `flag` = 32 | `send_raw_message(msg, 160)` |

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const sidebars = {
210210
'develop/smart-contracts/guidelines/ecosystem-messages-layout',
211211
'develop/smart-contracts/guidelines/message-delivery-guarantees',
212212
'develop/smart-contracts/messages',
213+
'develop/smart-contracts/guidelines/message-modes-cookbook',
213214
'develop/smart-contracts/guidelines/internal-messages',
214215
'develop/smart-contracts/guidelines/external-messages',
215216
'develop/smart-contracts/guidelines/non-bouncable-messages',

static/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance_and_destroy_sc.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_all_received_tokens_with_balance_and_if_error_bounce.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_regular_and_pay_fees_separately.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_regular_message.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_regular_message_and_bounce_if_error.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_regular_message_and_ignore_errors.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/send_regular_message_pay_fee_separately_bounce_if_error.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/сarry_all_the_remaining_value.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_if_error_bounce.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_pay_fees_separately.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/docs/message-modes-cookbook/сarry_all_the_remaining_value_and_pay_fees_separately_and_if_error_bounce.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)