Solidity is to Ethereum what Tact is to TON: How to create a voting smart contract on TON

Learn to develop smart contracts on the TON blockchain with Tact, an accessible and powerful language. Follow this step-by-step guide to create a voting contract using the TON Web IDE.

lunes, 24 de marzo de 2025 • 2 min read • Q2BSTUDIO Team

Company-Software-Apps-ArtificialIntelligence

When most people start learning about smart contract development, the first thing they hear is Solidity and Ethereum. This makes sense, as Solidity enabled blockchain programming and Ethereum became the go-to platform for many developers.

However, Solidity is not the only language for smart contracts, nor is Ethereum the only blockchain that supports decentralized applications.

There is also TON (The Open Network), a fast and lightweight blockchain originally created by Telegram, but now managed by the community. TON takes a different approach from Ethereum and offers multiple languages for developing smart contracts, including Tact, Tolk, FunC, and Fift. In this guide, we will explore Tact and learn how to build a voting contract with it.

Why choose Tact?

TON offers several languages depending on the level of abstraction and developer experience:

  • FunC: TON's traditional, low-level language that gives precise control over the contract. Similar to C, it requires knowledge of the TON Virtual Machine (TVM).
  • Fift: A stack-based language used to interact with the TVM, for deployment and debugging. It is not ideal for writing full contracts.
  • Tolk: An evolving language that aims to improve tooling and compatibility with high-level languages.
  • Tact: A high-level language that simplifies contract development on TON, with a friendly syntax similar to TypeScript or Solidity.

How Tact works

A contract in Tact follows this structure:

  • contract: Defines the name and state variables.
  • init: Initializes the variables and conditions of the contract upon deployment.
  • receive: Acts as a 'listener' for incoming messages.
  • get fun: Read-only methods to query the contract state.

Tact uses message-based communication, meaning each contract processes messages in its receive block. This allows for structured and maintainable organization.

Building a voting contract

The goal is to create a contract that allows users to cast votes and verify results on the blockchain.

Steps:

  • Open the TON Web IDE: Create a new project with Tact.
  • Write the contract code: Define a message structure for voting and create state variables (votesAlice and votesBob).
  • Implement the voting logic: Increment the appropriate counter based on the received message.
  • Add query functions: Methods to retrieve the number of votes.

Deploy and test the contract

From the IDE:

  • Compile and deploy the contract in the sandbox environment.
  • Cast votes via messages and query results using the created functions.

Conclusion

With this example, you have taken a first step in development with Tact on TON. Although this contract is basic, the principles can be applied to more complex logic.

At Q2BSTUDIO, we are experts in developing technological and blockchain solutions. If you are looking to take your projects to the next level with decentralized technology, contact us to develop customized and efficient solutions. We are ready to innovate with you!

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.