Skip to content

Commit 3b8709d

Browse files
authored
feat(docs): receivers accept all incoming funds and the amount of received native, Toncoin funds can be checked with context().value (#3378)
1 parent 8511cfc commit 3b8709d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/src/content/docs/book/receive.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,33 @@ Note that the receiver `receive(msg: Slice){:tact}` acts as a fallback that catc
5656

5757
If there is no receiver to process a message type and the fallback receiver `receive(msg: Slice){:tact}` is not declared, the transaction will fail with exit code [130](/book/exit-codes/#130).
5858

59+
Receivers accept all incoming funds by default. That is, without explicitly sending a message that will refund spare Toncoin with the [`cashback(){:tact}`](/ref/core-send#cashback) function, all the incoming message value will be kept by the contract.
60+
61+
Receivers accept all incoming funds by default. That is, without explicitly sending a message that will refund spare Toncoin with the [`cashback(){:tact}`](/ref/core-send#cashback) function, the contract will keep all the incoming message value.
62+
63+
To check the amount of Toncoin (native coins) the incoming message carries with it, you can use the [`context(){:tact}`](/ref/core-contextstate#context) function and access the `value` field of its resulting [struct](/book/structs-and-messages#structs). Note, however, that the exact value by which the balance will be increased will be less than `context().value{:tact}` since the [compute fee](https://docs.ton.org/v3/documentation/smart-contracts/transaction-fees/fees-low-level#computation-fees) for contract execution will be deducted from this value.
64+
65+
```tact /context\(\).value/
66+
contract WalletV4(
67+
// ...contract variables...
68+
) {
69+
// ...
70+
receive(msg: PluginRequestFunds) {
71+
require(
72+
myBalance() - context().value >= msg.amount,
73+
"The balance is too low to fulfill the plugin request!",
74+
);
75+
// ...
76+
}
77+
}
78+
79+
message(0x706c7567) PluginRequestFunds {
80+
queryId: Int as uint64;
81+
amount: Int as coins;
82+
extra: Cell?;
83+
}
84+
```
85+
5986
Naming the parameter of a receiver function with an underscore `_{:tact}` makes its value considered unused and discarded. This is useful when you don't need to inspect the message received and only want it to convey a specific opcode:
6087

6188
```tact

0 commit comments

Comments
 (0)