The new Tact v1.3 release provides a massive improvement on the smart contract programming for TON blockchain.
🗺 Maps
Traversing a map has never been easier! The
foreach loop for the Map type:
let mapLength: Int = 0;
foreach (k, v in map) {
mapLength += 1;
}
You don't have to use
map.set(key, null) to remove a key from your maps, use the more intuitive del method instead: map.del(key).Want to check if the map is empty? Use
map.isEmpty()!🔤 Strings
Strings finally support escape sequences, like \\, \", \n, \u0000 through \uFFFF, etc.
There is a new non-modifying StringBuilder's concat method for chained string concatenations:
b = b.concat("Hello,").concat(foo).concat("Tact!").We added the
toString method for the Address type that you asked for numerous times in the dev chats: address("EQBKgXCNLPexWhs2L79kiARR1phGH1LwXxRbNsCFF9doc2lN").toString().👌 Handling exceptions
Want to process various TVM and user-defined exit codes before your contract fails at runtime? The
try and try-catch statements: https://docs.tact-lang.org/book/statements#try-catch:
try {
let foo: Int = 42 / 0;
} catch(e) {
// your division by zero handler
}
☀️ New quality-of-life improving syntax
Tact started supporting struct fields punning, i.e.
{foo, bar} is syntactic sugar for { foo: foo, bar: bar }.There is support for trailing commas in all comma-separated lists in Tact, here is how you can use it with structs:
foo(Struct {
field1: 42,
field2: "42",
})
You can now chain method calls with the unboxing operator
!!, e.g. map.asCell()!!.hash().For those missing some bit-level hackery, there is the bitwise XOR operator
^ available now.⚙️ Stdlib enhancements
The Tact team has added
log2 and log, pow2 and pow functions.Use reserve mode constants from @stdlib/reserve instead of their numeric values to make your code even easier to read: https://docs.tact-lang.org/ref/core-advanced#nativereserve-base-modes.
🧠 Debugging
Debugging has become easier now as the
dump() and dumpStack() functions now print the file path, line number, and column number in addition to the data specified by the programmer.Addresses can be arguments of the dump function.
💻 Tact CLI
Tact's command line interface just became a lot more user-friendly: run
npx tact --help from terminal and see what's available.Just a highlight: CLI now allows compiling a single Tact file directly, without specifying a config file:
npx tact your-awesome-contract.tact. It's very useful for quick experiments or bug reports.🛠 Third-party tools support
For third-party tools implementors there is new improved APIs: AST traversals, access to the AST store of top-level items like functions, constants, traits, etc.
Happy hacking! ❤️
Check out Tact's CHANGELOG for the comprehensive list of features, changes and bugfixes.
Check out the Tact docs and read about the new Tact features.
To upgrade your Blueprint-based Tact projects to use Tact v1.3.1, run npm upgrade inside the project folder.
This release was brought to you by 0kenx, byakuren-hijiri, Max Korsunov, Novus Nota, Vitor Py, Daniil Sedov, and Anton Trunov.