This is an introductory article on the development of smart contracts for the Free TON blockchain. Here we will help you prepare for the development of the first smart contracts, consider setting up the development environment. We will focus on contracts in the Solidity language, as this is the easiest way to get acquainted with the blockchain.
Solidity was originally developed for the Ethereum blockchain. But fortunately, the craftsmen have ported the compiler for the TON virtual machine.
A very important file that will certainly come in handy in the future: https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md - documentation for all functions in TON-Solidity. It is worth noting that there are enough differences from etheric solidity here, so you will have to refer to this document often.
Setting up the environment
So, to get started easily, we need:
Installing all this is quite simple. If you have not installed packages via npm before, then to install the console TONDEV, open the console and run the command
npm i -g tondev
After installing the required programs, we need to deploy the local blockchain. To do this, open the console and write:
tondev se start
This command will download and install a TON OS SE image with a testnet already configured.
Next, install the tonos-cli console utility to interact with the blockchain:
tondev tonos-cli install
Now let's check if everything works
tonos-cli -u http://localhost account 0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94
-u http://localhost indicates that we are connecting to the local blockchain.
0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94- this is the default giver address. It stores all the coins on the testnet. And in the future, we will use it when we test contracts.
We must receive such an answer. If everything is ok, then Docker is working fine and everything is installed.
Creating Hello Wold
TONDEV has demo projects, to see them run
tondev js demo
To create Hello World project run
tondev js demo hello
in the directory where you want to place the future project.
Now let's move on to Visual Studio Code, where we will write the code. Open the project folder.
We can see that the project already has a Hello.sol contract and JS code with the SDK that works with this contract.
To run the project, you need to install the dependencies:
We will take a closer look at working with smart contracts in the next article.