TON (The Open Network), formerly known as Telegram Open Network, is a decentralized blockchain platform developed by the Telegram team.
Ton may be the next hot spot. Recently, we can see the prosperity of the ecology on the ton chain, mainly some small games, relying on a huge user group, and ton is in a very early stage, which brings us a very rich imagination space, among which The ton token has also soared to a maximum of 8U, which is enough to show its popularity. Since the ton ecology is completely different from the evm ecology, we will start with a simple contract deployment to introduce you to the ton contract and ecology.
It is recommended to use tonkeeper wallet, which supports installation on telegram. This is different from other wallets. However, according to custom, we install it in the browser.
https://t.me/testgiver_ton_bot
Get test tokens through telegram bot
Similar to remix, the ton ecosystem also provides online development tools. Here we use nujan ide
Note that ton supports two languages, tact and func, among which tact will eventually be compiled into func. tact is also more suitable for getting started. Here we use the tact language.
Dependencies and imports
This line of code is equivalent to telling the system that we need to use a tool package called “@stdlib/deploy”, which is to enable our contract to be deployed and run normally.
Message definition
A message type called Add is defined here. There are two things in this message:
• queryId: This is an ID used to uniquely identify the message, which looks a bit like a sequence number.
• amount: This is the value we want to add to the counter.
Contract definition
TactCounter is the name of our smart contract, which can be deployed. There are two variables in it:
• id: The ID of the contract, used to identify this contract, similar to an ID number.
• counter: This is our counter, the initial value is 0.
Initialization method
How to receive messages
This method will be called when the TactCounter contract receives an Add message. There is a value amount in the message, which will be added to our counter.
How to get attributes
This part defines two methods for viewing contract status:
• counter(): returns the current counter value.
• id(): Returns the ID of this contract.
Summarize
In short,This code implements a simple smart contract called TactCounter. this contract that is one counter, can record a value. When you send an Add message to it, it will update the value. In addition, it can also tell you what the current value of the counter is and what the ID of this contract is.
This tact code is quite similar to solidity, so you may be familiar with it.
Select testnet for deployment. Like remix, you can select testnet for deployment.
Note that tonkeeper switches the test network in a special way. Click the logo 5 times.
subsequently deployedcontract:
subsequently can see our contract already deployed in test net now