Tact doesn't support classical class inheritance, but contracts can implement traits.
One commonly used trait is Deployable
, which implements a simple receiver for the Deploy
message. This helps deploy contracts in a standardized manner.
All contracts are deployed by sending them a message. While any message can be used for this purpose, best practice is to use the special Deploy
message.
This message has a single field, queryId
, provided by the deployer (usually set to zero). If the deployment succeeds, the contract will reply with a DeployOk
message and echo the same queryId
in the response.
If you're using Tact's auto-generated TypeScript classes to deploy, sending the deploy message should look like:
const msg = { $$type: "Deploy", queryId: 0n };
await contract.send(sender, { value: toNano(1) }, msg);
You can see the implementation of the trait here. Notice that the file deploy.tact needs to be imported from the standard library using the import
keyword.
import "@stdlib/deploy"; contract Addresses with Deployable { // contract persistent state variables // we have three representations of the same address a1: Address = address("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"); // bouncable (same foundation wallet) a2: Address = address("UQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqEBI"); // non-bounceable (same foundation wallet) a3: Address; a4: Address; a5: Address; a6: Address; init() { // this is the third representation of the same address self.a3 = newAddress(0, 0x83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8); // raw (same foundation wallet) // here are a few other important addresses self.a4 = newAddress(0, 0); // the zero address (nobody) self.a5 = myAddress(); // address of this contract self.a6 = sender(); // address of the deployer (the sender during init()) } receive("show all") { /// addresses cannot currently be dumped /// TODO: https://github.com/tact-lang/tact/issues/16 /// dump(self.a1); } receive("show ops") { // temporary variable let a: Address = address("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"); // bouncable (same foundation wallet) dump(a == self.a1); dump(a == self.a2); dump(a == self.a3); dump(a == self.a4); dump(a != self.a5); } get fun result(): Address { return self.a1; } }