Welcome to Tact
Tact is a new programming language for TON blockchain that is focused on efficiency and simplicity. It is designed to be easy to learn and use, and to be a good fit for smart contracts. Tact is a statically typed language with a simple syntax and a powerful type system.
Getting started from template
To get started, you can use the template project. It contains a simple contract that can be deployed to the TON blockchain, example of implementing unit tests and helper functions for contract deployment.
To create a project from template, just create a new repository from the template project: https://github.com/ton-core/tact-template (opens in a new tab).
Getting started from scratch
Tact is distributed via npm
package manager and is meant to be installed to typescript/javascript projects:
yarn add tact
Then you need to create a tact.config.json
file in the root of your project. It should contain the following:
{
"projects": [{
"name": "sample",
"path": "./sources/contract.tact",
"output": "./sources/output"
}]
}
Add an example contract to ./sources/contract.tact
:
import "@stdlib/deploy";
message Add {
amount: Int as uint32;
}
contract SampleTactContract with Deployable {
owner: Address;
counter: Int as uint32;
init(owner: Address) {
self.owner = owner;
self.counter = 0;
}
fun add(v: Int) {
// Check sender
let ctx: Context = context();
require(ctx.sender == self.owner, "Invalid sender");
// Update counter
self.counter = (self.counter + v);
}
receive(msg: Add) {
self.add(msg.amount);
}
receive("increment") {
self.add(1);
}
get fun counter(): Int {
return self.counter;
}
}
Add a build script to package.json
:
{
"scripts": {
"build": "tact --config ./tact.config.json",
}
}
Now you can run yarn build
and get the compiled contract in ./sources/output
folder.