Base trait
Every contract in Tact implicitly inherits the BaseTrait
trait, which contains a number of internal functions for any contract and a constant self.storageReserve
aimed at advanced users of Tact.
Constants
self.storageReserve
virtual const storageReserve: Int = 0;
Usage example:
contract AllYourStorageBelongsToUs { // This would change the behavior of the self.forward() function, // causing it to try reserving this amount of nanoToncoins before // forwarding a message with SendRemainingBalance mode override const storageReserve: Int = ton("0.1");}
Functions
self.reply
virtual fun reply(body: Cell?);
An alias to calling the self.forward()
function with the following arguments:
self.forward(sender(), body, true, null);// ↑ ↑ ↑ ↑// | | | init: StateInit?// | | bounce: Bool// | body: Cell?// to: Address
Usage example:
// This message can bounce back to us!self.reply("Beware, this is my reply to you!".asComment());
self.notify
virtual fun notify(body: Cell?);
An alias to calling the self.forward()
function with the following arguments:
self.forward(sender(), body, false, null);// ↑ ↑ ↑ ↑// | | | init: StateInit?// | | bounce: Bool// | body: Cell?// to: Address
Usage example:
// This message won't bounce!self.notify("Beware, this is my reply to you!".asComment());
self.forward
virtual fun forward(to: Address, body: Cell?, bounce: Bool, init: StateInit?);
Queues the message (bounceable or non-bounceable) to be sent to the specified address to
. Optionally, you may provide a body
for the message and the init
package.
When the self.storageReserve
constant is overridden to be greater than 0, it also attempts to reserve the self.storageReserve
amount of nanoToncoins from the remaining balance before sending the message in the SendRemainingBalance
() mode.
In case the reservation attempt fails, or in the default case without the attempt, the message is sent with the SendRemainingValue
() mode instead.
Usage example:
import "@stdlib/ownable";
message PayoutOk { address: Address; value: Int as coins;}
contract Payout with Ownable { completed: Bool; owner: Address;
init(owner: Address) { self.owner = owner; self.completed = false; }
// ... some actions here ...
// Bounced receiver function, which is called when the specified outgoing message bounces back bounced(msg: bounced<PayoutOk>) { // Reset completed flag if our message bounced self.completed = false;
// Send a notification that the payout failed, using the remaining funds to process this send self.forward(self.owner, "Payout failed".asComment(), false, null); }}