How-to: Getting started with smart contracts. Preparation. : TON Tips

How-to: Getting started with smart contracts. Preparation.

Setting up the environment, installing programs.


Posted by Team Tips on 04 Jun 2021

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: - 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:

VisualStudio Code - IDE
Plugin Tondev
Node.js and NPM
Console tool TONDEV

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
Argument -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 runtondev js demo

To create Hello World project runtondev 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: npm install

We will take a closer look at working with smart contracts in the next article.