-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proofread Nodes & Modes #967
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Message Modes Cookbook | ||
|
||
Understanding the different modes and flags available for sending messages is crucial to ensure that your smart contracts behave as intended. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
While [message modes](/v3/documentation/smart-contracts/message-management/sending-messages#message-modes) section provided detailed descriptions of these modes and flags, in this section we will illustrate their practical application through specific examples. | ||
While the [message modes](/v3/documentation/smart-contracts/message-management/sending-messages#message-modes) section provides detailed descriptions of these modes and flags, in this section we will illustrate their practical application through specific examples. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems better for reading: |
||
|
||
:::info IMPORTANT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to point to this example here? Looks not clear, how this example will help readers, who just opened page. |
||
You can check [this example](https://testnet.tonviewer.com/transaction/42ed45726e4fe994b7fd6dbf953a2ac24ecd77753858abeda9d6755c664a537a) as a real-world validation. | ||
|
@@ -11,23 +11,23 @@ You can check [this example](https://testnet.tonviewer.com/transaction/42ed45726 | |
|
||
Please check how [get_balance](/v3/documentation/smart-contracts/func/docs/stdlib/#get_balance) works to better understand `balance` inside TVM. | ||
|
||
All TON tokens owned by a contract are reflected in the [contract balance](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/block.tlb#L263C1-L265C20). Some of these tokens are also attributed to the currently processed incoming [message](/v3/documentation/data-formats/tlb/msg-tlb#commonmsginfo) - a mechanism that works effectively because any TON transaction involving a [non-system contract](/v3/documentation/smart-contracts/contracts-specs/governance) processes exactly one incoming message at a time. | ||
All TON tokens owned by a contract are reflected in the [contract balance](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/block.tlb#L263C1-L265C20). Some of these tokens are also attributed to the currently processed incoming [message](/v3/documentation/data-formats/tlb/msg-tlb#commonmsginfo) — a mechanism that works effectively because any TON transaction involving a [non-system contract](/v3/documentation/smart-contracts/contracts-specs/governance) processes exactly one incoming message at a time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples are really helpful, and links should be provided. However, let's maintain a balance, such as one link per paragraph or about three links per page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use active voice: A contract's [balance](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/block.tlb#L263C1-L265C20) reflects all TON tokens it owns. This approach effectively attributes some of these tokens to the currently processed incoming [message](/v3/documentation/data-formats/tlb/msg-tlb#commonmsginfo) because any TON transaction involving a non-system contract processes exactly one incoming message at a time. |
||
|
||
Therefore, any blockchain payment may come either: | ||
|
||
- From the incoming message `value`. | ||
For instance, computation fees are paid in this way, unless contract calls [accept_message](v3/documentation/smart-contracts/transaction-fees/accept-message-effects). This ensures that malicious actors cannot spend contract's balance on handling their data. | ||
- From the contract `balance` (will not touch amount of TON designated as incoming this transaction). | ||
For instance, computation fees are paid in this way, unless the contract calls [accept_message](/v3/documentation/smart-contracts/transaction-fees/accept-message-effects). This ensures that malicious actors cannot spend the contract's balance on handling their data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cut unnecessary words: For instance, computation fees are paid this way unless the contract calls [accept_message](/v3/documentation/smart-contracts/transaction-fees/accept-message-effects). This ensures malicious actors cannot spend the contract's balance handling their data. |
||
- From the contract `balance` (will not touch the amount of TON designated as incoming this transaction). | ||
Storage fees in workchains 0 and -1, as well as most actions, are currently examples of this. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cut unnecessary words: Storage fees in workchains 0 and -1 and most actions are currently examples of this. |
||
|
||
#### Fees | ||
|
||
Actual transaction fees will vary depending on the blockchain configuration, the smart contract code and other factors. When a message is received, part of the contract `balance` will be consumed by [storage fees](/v3/documentation/smart-contracts/transaction-fees/fees-low-level#storage-fee) and gas_fees if the message `value` [is above certain amount](/v3/documentation/tvm/tvm-overview#compute-phase-skipped). | ||
Actual transaction fees will vary depending on the blockchain configuration, the smart contract code, and other factors. When a message is received, part of the contract `balance` will be consumed by [storage fees](/v3/documentation/smart-contracts/transaction-fees/fees-low-level#storage-fee) and gas fees if the message `value` [is above a certain amount](/v3/documentation/tvm/tvm-overview#compute-phase-skipped). | ||
|
||
According to the [transaction flow](/v3/documentation/tvm/tvm-overview#transactions-and-phases) there are 5 phases: | ||
According to the [transaction flow](/v3/documentation/tvm/tvm-overview#transactions-and-phases), there are 5 phases: | ||
|
||
- Storage, consisting of [account storage](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/transaction.cpp#L651-L675) and [in_msg import](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/transaction.cpp#L783-L816) | ||
- [Credit](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/transaction.cpp#L959-L981), where in_msg `value` is added to the `balance` | ||
- [Credit](https://github.com/ton-blockchain/ton/blob/7151ff26279fef6dcfa1f47fc0c5b63677ae2458/crypto/block/transaction.cpp#L959-L981), where the in_msg `value` is added to the `balance` | ||
- Compute, where the actual smart contract code is executed in TVM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use active voice: |
||
- Action, where actions like `SENDRAWMSG` are performed | ||
- Bounce, where everything about bouncing is handled | ||
|
@@ -40,17 +40,17 @@ The table is populated based on [this example](https://tonviewer.com/transaction | |
|
||
| Fee in Explorer | Value | How it's obtained | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use sentence case in the headers. |
||
| :------------------------------------------------------------------------------------------------ | :---------- | :------------------------------ | | ||
| Total fee | 0,001982134 | gas + storage + action + import | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalized |
||
| total_fwd_fees | 0,001 | fwd_fee + action_fee + ihr_fee | | ||
| gas_fees | 0,0011976 | compute phase, gas used | | ||
| storage_fees | 0,000000003 | storage phase, account only | | ||
| total_action_fees | 0,000133331 | action phase, cost per action | | ||
| import_fee (hidden) | 0,0006512 | cost of import of ext_msg | | ||
| [fwd_fee](/v3/documentation/smart-contracts/transaction-fees/fees-low-level#formula-1) (each msg) | 0,000266669 | cost of fwd of in_msg | | ||
| Total fee | 0.001982134 | gas + storage + action + import | | ||
| total_fwd_fees | 0.001 | fwd_fee + action_fee + ihr_fee | | ||
| gas_fees | 0.0011976 | compute phase, gas used | | ||
| storage_fees | 0.000000003 | storage phase, account only | | ||
| total_action_fees | 0.000133331 | action phase, cost per action | | ||
| import_fee (hidden) | 0.0006512 | cost of import of ext_msg | | ||
| [fwd_fee](/v3/documentation/smart-contracts/transaction-fees/fees-low-level#formula-1) (each msg) | 0.000266669 | cost of fwd of in_msg | | ||
| [ihr_fee](/v3/documentation/smart-contracts/transaction-fees/fees-low-level#ihr) (each msg) | 0.0006 | cost of ihr fwd of in_msg | | ||
|
||
:::info | ||
The transaction fees used in these examples are hypothetical and are for illustrative purposes only. Any fees other than message forwarding are out of scope of this article. | ||
The transaction fees used in these examples are hypothetical and are for illustrative purposes only. Any fees other than message forwarding are out of the scope of this article. | ||
Funds included with an ignored message will still be [credited to the receiving address](https://testnet.tonviewer.com/transaction/8a388731812c80ab9b0ea9531108425488af5def854e4bd6f0ed47362b56d557). | ||
::: | ||
|
||
|
@@ -73,7 +73,7 @@ State after transaction: Account A has 0.9 TON, Account B has 1.096 TON | |
State before transaction: Account A has 1 TON, Account B has 1 TON | ||
|
||
**A** sent 0.1 TON to **B**, `msg_fwd_fees` are 0.004 TON, actual received value will be 0.096 TON, `fwd_fee` and `action_fee` are deducted from `value`. | ||
In case of an error during [action phase](/v3/documentation/smart-contracts/message-management/sending-messages#message-modes), the message will be skipped instead of throwing an [exit code](/v3/documentation/tvm/tvm-exit-codes#standard-exit-codes). | ||
In case of an error during the [action phase](/v3/documentation/smart-contracts/message-management/sending-messages#message-modes), the message will be skipped instead of throwing an [exit code](/v3/documentation/tvm/tvm-exit-codes#standard-exit-codes). | ||
|
||
State after transaction: Account A has 0.9 TON, Account B has 1.096 TON | ||
|
||
|
@@ -92,14 +92,14 @@ If no errors occur, the result is the same as [`mode = 0`](#1-send-a-regular-mes | |
State before transaction: Account A has 1 TON, Account B has 1 TON | ||
|
||
**A** sent 0.1 TON to **B**, `msg_fwd_fees` are 0.004 TON, actual received value will be 0.096 TON, `fwd_fee` and `action_fee` are deducted from `value`. | ||
In case of an error during [action phase](https://retracer.ton.org/?tx=e9dccba82badc0d742f14eff41c203280f380e87180b5314fcfd742856e598f7&testnet=true), the message will bounce and `total_fee` + `fwd_fee` will be deducted from `value`. | ||
In case of an error during the [action phase](https://retracer.ton.org/?tx=e9dccba82badc0d742f14eff41c203280f380e87180b5314fcfd742856e598f7&testnet=true), the message will bounce and `total_fee` + `fwd_fee` will be deducted from `value`. | ||
|
||
State after transaction with error: Account A has 1 - ([total_fee](/v3/documentation/smart-contracts/transaction-fees/fees#basic-fees-formula) + `fwd_fee`) TON, Account B has 1 TON | ||
|
||
 | ||
|
||
:::info tip | ||
If no errors occur the result is the same as [`mode = 0`](#1-send-a-regular-message). | ||
If no errors occur, the result is the same as [`mode = 0`](#1-send-a-regular-message). | ||
::: | ||
|
||
 | ||
|
@@ -127,14 +127,14 @@ State after the transaction: Account A has 0.896 TON, Account B has 1.1 TON | |
State before the transaction: Account A has 1 TON, Account B has 1 TON | ||
|
||
**A** sent 0.1 TON to **B**, `msg_fwd_fees` are 0.004 TON, actual received value will be 0.1 TON, `fwd_fee` and `action_fee` are deducted from `balance`. | ||
In case of an error [during action phase](https://retracer.ton.org/?tx=e9dccba82badc0d742f14eff41c203280f380e87180b5314fcfd742856e598f7&testnet=true), the message will bounce and `total_fee` + `fwd_fee` will be deducted from `value`. | ||
In case of an error during the [action phase](https://retracer.ton.org/?tx=e9dccba82badc0d742f14eff41c203280f380e87180b5314fcfd742856e598f7&testnet=true), the message will bounce and `total_fee` + `fwd_fee` will be deducted from `value`. | ||
|
||
State after the transaction with an error: Account A has 1 - ([total_fee](/v3/documentation/smart-contracts/transaction-fees/fees#basic-fees-formula) + `fwd_fee`) TON, Account B has 1 TON | ||
|
||
 | ||
|
||
:::info tip | ||
If no errors occur the result is the same as [`mode = 1`](#4-send-a-regular-message-with-separate-fees). | ||
If no errors occur, the result is the same as [`mode = 1`](#4-send-a-regular-message-with-separate-fees). | ||
::: | ||
|
||
 | ||
|
@@ -153,13 +153,13 @@ State after the transaction: Account A has 0.896 TON, Account B has 0.5 TON, Acc | |
|
||
:::info | ||
You might check [this example](https://testnet.tonviewer.com/transaction/f63ab35f34e342cdd249f13018d5034ce3d80c488628d5a4db0a43163fa50adb). | ||
Please note that `storage_fee` is included in `total_fee` but it is always paid from contract `balance`. | ||
Please note that `storage_fee` is included in `total_fee`, but it is always paid from the contract `balance`. | ||
::: | ||
|
||
:::warning | ||
Please note that `SENDRAWMSG` doesn't update balance. | ||
Please note that `SENDRAWMSG` doesn't update the balance. | ||
|
||
If you try to send multiple messages (i.e. mode 0 **and** mode 64) you'll get exit code 37. | ||
If you try to send multiple messages (i.e., mode 0 **and** mode 64), you'll get exit code 37. | ||
::: | ||
|
||
 | ||
|
@@ -178,7 +178,7 @@ State after the transaction: Account A has 0.896 TON, Account B has 0.5 - (total | |
|
||
:::info | ||
You might check [this example](https://testnet.tonviewer.com/transaction/ad93e784453b573d737d9d928b4377ff3779177753e05629e54f6629556568ad). | ||
Please note that `storage_fee` is included in `total_fee` but it is always paid from contract `balance`. | ||
Please note that `storage_fee` is included in `total_fee`, but it is always paid from the contract `balance`. | ||
::: | ||
|
||
 | ||
|
@@ -199,7 +199,7 @@ State after the transaction with an error: Account A has 1 - (total_fee + `fwd_f | |
 | ||
|
||
:::info tip | ||
If no errors occur the result is the same as [`mode = 64`](#6-carry-remaining-value-with-new-message). This mode is widely used in TON for jetton transfers. You can [check it in C5 action list](https://retracer.ton.org/?tx=6489d60d9197c0be7ee64b0812139d82221e8f94c6e378c356acc10f9067310c) of the jetton wallet. | ||
If no errors occur, the result is the same as [`mode = 64`](#6-carry-remaining-value-with-new-message). This mode is widely used in TON for jetton transfers. You can [check it in C5 action list](https://retracer.ton.org/?tx=6489d60d9197c0be7ee64b0812139d82221e8f94c6e378c356acc10f9067310c) of the jetton wallet. | ||
::: | ||
|
||
 | ||
|
@@ -213,14 +213,14 @@ If no errors occur the result is the same as [`mode = 64`](#6-carry-remaining-va | |
State before the transaction: Account A has 1 TON, Account B has 1 TON, Account C has 1 TON | ||
|
||
**A** sent 0.1 TON to **B** after that **B** sent 0.5 TON to **C** with `mode` = 81, `msg_fwd_fees` are 0.004 TON, actual received value will be 0.6 TON, total_fee + `fwd_fee` are deducted from `balance`. | ||
In case of an error during the action phase, the message will bounce and `total_fee` + `fwd_fee` will be are deducted from `value`. | ||
In case of an error during the action phase, the message will bounce and `total_fee` + `fwd_fee` will be deducted from `value`. | ||
|
||
State after transaction with an error: Account A has 1 - (total_fee + `fwd_fee`) TON, Account B has 1 TON, Account C has 1 TON | ||
State after the transaction with an error: Account A has 1 - (total_fee + `fwd_fee`) TON, Account B has 1 TON, Account C has 1 TON | ||
|
||
 | ||
|
||
:::info tip | ||
If no errors occur the result is the same as [`mode = 65`](#7-carry-remaining-value-with-new-message-with-separate-fees). | ||
If no errors occur, the result is the same as [`mode = 65`](#7-carry-remaining-value-with-new-message-with-separate-fees). | ||
::: | ||
|
||
 | ||
|
@@ -254,7 +254,7 @@ State after the transaction with an error: Account A has 1 - (total_fee + `fwd_f | |
 | ||
|
||
:::info tip | ||
If no errors occur the result is the same as [`mode = 128`](#10-send-all-received-tokens-together-with-the-contract-balance). This mode is widely used in TON for jetton transfers, you can [check it in C5 action list](https://retracer.ton.org/?tx=e4f31e37eec74a8cfcecdad9246a6bbf3da20c4edb3635150cb0fa54b9def558) of the jetton wallet. | ||
If no errors occur, the result is the same as [`mode = 128`](#10-send-all-received-tokens-together-with-the-contract-balance). This mode is widely used in TON for jetton transfers. You can [check it in C5 action list](https://retracer.ton.org/?tx=e4f31e37eec74a8cfcecdad9246a6bbf3da20c4edb3635150cb0fa54b9def558) of the jetton wallet. | ||
::: | ||
|
||
 | ||
|
@@ -267,11 +267,11 @@ If no errors occur the result is the same as [`mode = 128`](#10-send-all-receive | |
|
||
State before the transaction: Account A has 1 TON, Account B has 1 TON, Account C has 1 TON | ||
|
||
**A** sent 0.1 TON to **B** after that **B** sent 0.5 TON to **C** with `mode` = 160, `msg_fwd_fees` are 0.004 TON, actual received value will be 1.1 - total_fee TON, total_fee deducted from `value`. | ||
**A** sent 0.1 TON to **B** after that **B** sent 0.5 TON to **C** with `mode` = 160, `msg_fwd_fees` are 0.004 TON, actual received value will be 1.1 - total_fee TON, total_fee is deducted from `value`. | ||
|
||
State after the transaction: Account A has 0.896 TON, Account B has 0 TON and `nonexist`, Account C has 2.1 - (total_fee + `fwd_fee`) TON | ||
|
||
When the balance reaches 0 TON, destroy the contract. | ||
When the balance reaches 0 TON, the contract is destroyed. | ||
|
||
 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentence case