Reference
Base trait

Base trait

Every contract and trait in Tact implicitly inherits the BaseTrait trait, which contains a number of the most useful internal functions for any kind of 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 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 of the message and the init package.

When self.storageReserve constant is overwritten to be >0> 0, before sending a message it also tries to reserve the self.storageReserve amount of nanoToncoins from the remaining balance before making the send in the SendRemainingBalance (opens in a new tab) (128128) mode.

In case reservation attempt fails and in the default case without the attempt, the message is sent with the SendRemainingValue (opens in a new tab) (6464) mode instead.

💡

Note, that self.forward() never sends additional nanoToncoins on top of what's available on the balance.
To be able to send more nanoToncoins with a single message, use the the send() function.

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 there ...
 
    // 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 for processing this send
        self.forward(self.owner, "Payout failed".asComment(), false, null);
    }
}