Most of the messages we saw in the previous example were defined with the message
keyword. They are considered binary messages. This means that when somebody wants to send them, they serialize them into bits and bytes of binary data.
The disadvantage with binary messages is that they're not human readable.
When working with dangerous contracts that handle a lot of money, users are encouraged to use hardware wallets like Ledger. Hardware wallets cannot decode binary messages to confirm to the user what they're actually signing.
Tact supports textual messages for this reason, since they're human readable and can easily be confirmed with users, eliminating phishing risks.
Textual messages are limited because they cannot contain arguments. Future versions of Tact will add this functionality.
If you've ever made a transfer using a TON wallet, you probably noticed that you can add a comment (also known as a memo or a tag). This is how textual messages are sent.
Receivers for textual messages just define the string that they expect. Tact automatically does string matching and calls the matching receiver when a comment message arrives.
All Examplesimport "@stdlib/deploy"; // this contract records the last 5 timestamps of when "timer" message was received contract Arrays with Deployable { const MaxSize: Int = 5; arr: map; // this is our array implemented with a map arrLength: Int as uint8 = 0; arrStart: Int as uint8 = 0; // our array is cyclic init() {} // push an item to the end of the array fun arrPush(item: Int) { if (self.arrLength < self.MaxSize) { self.arr.set(self.arrLength, item); self.arrLength = self.arrLength + 1; } else { self.arr.set(self.arrStart, item); self.arrStart = (self.arrStart + 1) % self.MaxSize; } } // iterate over all items in the array and dump them fun arrPrint() { let i: Int = self.arrStart; repeat (self.arrLength) { dump(self.arr.get(i)!!); // !! tells the compiler this can't be null i = (i + 1) % self.MaxSize; } } // record the timestamp when each "timer" message is received receive("timer") { let timestamp: Int = now(); self.arrPush(timestamp); } receive("dump") { self.arrPrint(); } get fun length(): Int { return self.arrLength; } get fun map(): map { return self.arr; } }