Acton

Quickstart

Build, test, and deploy your first Tolk smart contract with Acton

In this guide, we will explore Acton's capabilities and develop a simple smart contract. We'll write tests, deploy it to the testnet, and verify its source code.

We won't dive deep into the specific details of the contract logic here. To learn more about Tolk and smart contract development, check out Your first smart contract in the official documentation.

Already have a repository?

This quickstart uses acton new because it is the fastest way to get a working sample project. If you are adding Acton to an existing repository instead, start with acton init and then come back to the build/test/deploy steps below. The existing-project flow is documented in Project initialization.

Get started

First, let's create a directory for our project. Acton provides the acton new command to scaffold a new project. We'll use the counter template which comes with a pre-configured contract, tests, and deployment script.

acton new first_counter --template counter

This will create a new directory first_counter with the project structure. You should see output similar to this:

$ acton new first_counter --template counter
 Created new Acton project
  Project name: first_counter
  Description: A TON blockchain project
  Template: counter
  License: MIT

Created Acton.toml with project configuration
Created .acton/ directory with standard library
Created .acton/tolk-stdlib directory with Tolk standard library

Navigate to the project folder:

cd first_counter

The project is already set up with contracts/Counter.tolk and contracts/types.tolk. The generated Acton.toml also includes ready-to-run script aliases:

  • deploy-emulation
  • deploy-testnet

Since the template already configured Acton.toml, you can immediately build the contract:

acton build

This command compiles the contract and places the build artifacts (including a JSON report) in the build/ folder.

build/Counter.json
{
  "code_boc64": "te6ccgEBBAEAbwABFP8A9KQT9Lzy...",
  "hash": "1F6548A25E04497496242AD7804B653E6DA9A47E474DC17436313FFA04E15F18"
}

Congratulations! You've successfully built your first contract with Acton.

Acton includes a powerful test runner that allows you to write tests in Tolk. The template includes a test file tests/counter.test.tolk and generated wrappers in wrappers/.

Let's look at the included test in tests/counter.test.tolk:

tests/counter.test.tolk
get fun `test increase counter`() {
    val (counter, deployer, _) = setupTest();

    val res = counter.sendIncreaseCounter(deployer.address, 123);
    expect(res).toHaveSuccessfulTx<IncreaseCounter>({
        from: deployer.address,
        to: counter.address
    });

    expect(counter.currentCounter()).toEqual(123)
}

Run the tests:

acton test

Output:

$ acton test
   Compiling contracts
    Finished in 726.375µs
     Running tests

 TEST  <root>/first_counter

 > ./tests/counter.test.tolk (3 tests)
 increase-counter 4ms
 reset-counter 3ms
 unknown-message 2ms

 3 passed in 1 file

Acton also supports coverage analysis:

acton test --coverage

And mutation testing to find gaps in your tests:

acton test --mutate --mutate-contract Counter

To deploy to the blockchain, you first need a wallet. Create one with:

acton wallet new --name deployer --local --airdrop

This creates a new wallet and saves its configuration to wallets.toml in your project root. By default, Acton stores the mnemonic in your system keyring/keychain when secure storage is available.

If secure storage is unavailable, or if you disable it with --secure false, your mnemonic will be written to wallets.toml. Never commit it to git. Acton adds it to .gitignore automatically.

After creating a wallet, the --airdrop flag automatically requests testnet funds from the configured faucet.

If you don't use --airdrop, or if the faucet request fails, you can still fund the wallet through the Testnet Giver Bot by sending it your wallet address.

For day-to-day work, the broader wallet lifecycle is also worth knowing:

  • acton wallet import to reuse an existing mnemonic
  • acton wallet list --balance to inspect configured wallets
  • acton wallet sign to sign an external body without running a script
  • acton wallet export-mnemonic for interactive export
  • acton wallet remove -y to remove a wallet non-interactively

The full reference is in Setup wallets and acton wallet.

Now that our contract is tested and we have a funded wallet, we can deploy it to the testnet.

The template includes a deployment script scripts/deploy.tolk:

scripts/deploy.tolk
import "@acton/io"
import "@acton/emulation/network"
import "@acton/emulation/scripts"
import "@acton/build"

import "@wrappers/Counter"
import "@contracts/types"

fun main() {
    val deployer = scripts.wallet("deployer");

    val counter = Counter.fromStorage({
        id: 0,
        counter: 0,
    });
    val res = counter.deploy(deployer.address, { value: ton("0.005") });
    if (!res.wait()) {
        return;
    }

    println("Deployed counter to {}", counter.address);
    println("On-chain counter is {}", counter.currentCounter());
}

Let's use it:

acton script scripts/deploy.tolk --net testnet

If successful, you'll see the deployment transaction hash, the contract address, and the freshly read on-chain counter value. The getter call works without a separate --fork-net because --net testnet now uses testnet for reads by default.

Finally, let's verify our contract source code on the blockchain explorer. This proves that the deployed bytecode matches your source code.

acton verify Counter --net testnet --address <YOUR_CONTRACT_ADDRESS>

Replace <YOUR_CONTRACT_ADDRESS> with the address from the previous step.

Congratulations! You've successfully built, tested, deployed, and verified a smart contract on the TON blockchain using Acton!

Troubleshooting

If build/test/wallet resolution does not match your expectations, run acton doctor before filing an issue. It prints resolved paths, manifest status, stdlib health, overlay status, native library metadata, and relevant environment variables.

Next Steps

Explore more advanced topics:

Last updated on

On this page