Deploy your smart contract

The Teloscope
Mar 20 · 5 min read

Here you will learn how to deploy your code on the Telos blockchain.

Part 5 of

DApp development tutorial for the Telos blockchain network

Part 1| Part 2| Part 3 | Part 4


In previous articles we have explained the structure of the contract, as well as its implementation. Now we will explain how to deploy the contract.

First you will have to install EOSIO in your system. Please visit the official EOS repository, where you will be able to see the commands required.

EOSIO can be installed in many operating systems, but we will base this article on Ubuntu 18.04 — or similar- which is very popular among developers.

For the installation of EOSIO you have to execute via console the commands described in the guide for Ubuntu 18.04 (Note: EOSIO version is 1.6.2. at the time of writing).

$ wget https://github.com/eosio/releases/download/v1.6.2/eosio_1.6.2-1-ubuntu-18.04_amd64.deb
$ sudo apt install ./eosio_1.6.2-1-ubuntu-18.04_amd64.deb

In order to check the correct installation, please execute the cleos command in the console. If the package was properly installed you should be presented with the image below:

After EOSIO installation, the following step is to create a wallet that will enable you to store your private keys. With them you will be able to sign the different operations that are made when interacting with the blockchain.

To create your wallet please execute the following command on the console.

$ cleos wallet create --file password.txt

This command will create a default wallet and store its password in the password.txt file. If you want to just print the password on console, instead of storing it on a file, you can use the following command:

$ cleos wallet create --to-console

Once the wallet is created you proceed to import the private key of the TLOS account that you want to use. Since we’ll be testing you can create your account using the Telos Foundation Account Creator. This creator will ask for a public key along with the account name, so you can use the Telos Foundation Key Generator to get a public/private key pair.

NOTE: The account creator will use the same key for the owner and active permission profiles. Best practices demand that we use different key pairs for each permission profile, so we should change either one. However, that’s out of the scope of this document.

Once you’ve created an account you need to import its private key into your wallet in order to be able to use it. First, unlock the wallet by issuing the following command:

$ cleos wallet unlock --password <PASSWORD>

Replacing <PASSWORD> with the wallet password created above.

The next step is to import the private key into the wallet.

$ cleos wallet import --private-key <PRIVATE_KEY>

Replacing <PRIVATE_KEY> with your private key.

At this point of the tutorial you have created a wallet and imported the private key of your account, so you are in the position to start operating with this account. However, you need some TLOS tokens to make it fully functional. Fortunately the Telos Foundation runs a Faucet that lets you get 200 TLOS per day, more than enough for this tutorial. Just type in the Faucet form your account name and click GET.

Once you’ve claimed the 200 TLOS you have to buy the most needed resource, which is RAM. Without enough RAM you won’t be able to deploy a contract. In this case you’ll need around 176kb of RAM. Well, round it up to 180kb. In order to buy it go to the console and use a real API TestNet node. The typical RAM buying command is this:

$ cleos -u <node_url> system buyram <RAM_PAYER> RAM_RECEIVER> -k <KB_AMOUNT>

And in this particular case:

$ cleos -u http://testnet.theteloscope.io:18888 system buyram  <your_account> <your_account> -k 180

Replacing <your_account> with the name of the account that you had created.

POWER-TIP: You can save some typing by creating an alias with the basic part of most of the cleos commands that you will be using :

$ alias cle='cleos -u http://testnet.theteloscope.io:18888'

Since you will also need CPU and NET resources you will have to stake 10 TLOS for each one. The basic command for that kind of operation is:

$ cle system delegatebw <PAYER> <RECEIVER> <TLOS_CPU_AMOUNT> <TLOS_NET_AMOUNT>

And in your case:

$ cle system delegatebw <your_account> <your_account> "10 TLOS" "10 TLOS"

As always replacing <your_account> with your account name.

Once you’ve reserved all necessary resources then compile the contract and deploy it to the Telos TestNet.

You must install the Contract Development Toolkit in order to compile contracts. It’s pretty much similar to what you did with the EOSIO binaries:

$ wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.5.0/eosio.cdt_1.5.0-1_amd64.deb
$ sudo apt install ./eosio.cdt_1.5.0-1_amd64.deb

Once installed, you can compile the contract from previous parts of this tutorial by running, in the directory where the contract and header files are stored, the following command:

$ eosio-cpp -abigen sensordapper.cpp -o sensordapper.wasm

This will generate the compiled WASM binary file (sensordapper.wasm) and the ABI file (sensordapper.abi) that are needed for the next step.

Once the contract has been successfully compiled, you have to deploy it to the Telos network. The typical command for contract deployment is:

$ cle set contract <CONTRACT_ACCOUNT> <CONTRACT_NAME_FOLDER_ROUTE> -p <ACTIVE_KEY>

In this case, if you run the command from the directory where the compiled files are stored, and let’s say you want to deploy it to an account called “sensordapper”, the command is:

$ cle set contract sensordapper ./sensordapper -p sensordapper@active

Congratulations, you’ve finally gotten your first smart contract deployed!

We will leave the final part of this tutorial for next article. Meanwhile you can connect directly with us and the community of creators and developers of DApps for Telos at the Telos Dapp Development telegram group.

This tutorial has been created by members of The Teloscope team.


The Teloscope is an independent nonprofit Telos block producer — our work is free from the influence of crypto whales or other BPs. The revenue we get from any service we provide to the Telos network is fully invested in our Telos BP infrastructure, as well as in tools and services for the blockchain community.

You can support us by including theteloscope among the list of BPs that deserve your vote.

TheTeloscope

The Non-Profit Block Producer Candidate | Visit our website at theteloscope.io

The Teloscope

Written by

theteloscope.io is a non-profit EOSIO Block Producer

TheTeloscope

The Non-Profit Block Producer Candidate | Visit our website at theteloscope.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade