Beginner’s Guide to EOS and Basic Smart Contracts featured
Beginner’s Guide to EOS and Basic Smart Contracts featured

Beginner’s Guide to EOS and Basic Smart Contracts

1. What is Eosio?

Eosio is software that introduces a blockchain architecture and claims to be a decentralized operating system which supports Dapps, it has developed under an open-source MIT software license. Block.one has built the eosio software, it is a leading blockchain solution company that provides high-performance blockchain solution.

The software provides accounts, authentication, databases, asynchronous communication and the scheduling of applications across multiple CPU cores and/or clusters.

2. How Eosio is different from other Blockchain (mainly Ethereum)?

Eosio is more scalable as it claims to manage millions of transaction per second, they are claiming this because they use DPOS(delegated proof of stake) consensus mechanism.
EOS provides parallel processing of smart contracts through horizontal scalability, they achieve horizontal scalability by adding more system to the resource pool.
They are planning to completely remove transaction fees, Eos works on an ownership model whereby users own and are entitled to use resources proportional to their stake, rather than having to pay for every transaction.

Also, Read Our Next Article on smart contracts

Prior knowledge required:

C/C++ intermediate experience
Blockchain Conceptual knowledge
Linux or command line tool

Architecture of EOSIO

Beginner’s Guide to EOS and Basic Smart Contracts

All the terms in the architecture diagram will be explained later on when it is required don’t get confused with the diagram.

Firstly you need to setup the environment and have to install all the dependencies and contract development toolkit to create wallet and accounts on EOS blockchain.

3. Setup Environment

3.1) Download dependencies:

Docker

3.2) Setup a development directory

Command :

Mkdir EOStest

Cd EOStest

Basic Smart Contracts

3.3) Get the Dockers image

The below statement will download an Ubuntu image which contains the compiled software.

docker pull eosio/eos:v1.4.2

Beginner’s Guide

3.4) Boot node and Wallet

Command :

docker run — name eosio \
 — publish 8888:8888 \
 — publish 127.0.0.1:5555:5555 \
 — volume /home/abhi_21094/Desktop/EOStest:/home/abhi_21094/Desktop/EOStest \
 — detach \
eosio/eos:v1.4.2 \
/bin/bash -c \
“keosd — http-server-address=0.0.0.0:5555 & exec nodeos -e -p eosio — plugin eosio::producer_plugin — plugin eosio::chain_api_plugin — plugin eosio::history_plugin — plugin eosio::history_api_plugin — plugin eosio::http_plugin -d /mnt/dev/data — config-dir /mnt/dev/config — http-server-address=0.0.0.0:8888 — access-control-allow-origin=* — contracts-console — http-validate-host=false — filter-on=’*’”

Guide

These settings accomplish the following:

  1. Forward port 8888 and 5555 to host machine
  2. Alias a work volume on your local drive to the docker container.
  3. Run the Nodeos startup in bash. This command loads all the basic plugins, set the server address, enable CORS and add some contract debugging.
  4. Enable CORS with no restrictions (*)

3.5) Check the Installation

Command :

docker logs — tail 10 eosio

Beginner’s Guide to EOS and Basic Smart Contracts 4

3.6) Check the Wallet

Open a new tab in the terminal

Command :

docker exec -it eosio bash
cleos — wallet-url http://127.0.0.1:5555 wallet list

Beginner’s Guide to EOS and Basic Smart Contracts 5

As now keosd is running successfully, now you should know the following terms that we will use during installation and also while developing.

What is Cleos?

(cli + eos = cleos) — command line interface to interact with the blockchain and to manage wallets.

What is Nodeos?

nodeos (node + eos = nodeos) — the core EOSIO node daemon that can be configured with plugins to run a node.

What is Keosd?

(key + eos = keosd) — component that securely stores EOSIO keys in wallets.

3.7) Check Nodeos endpoints

This will check that RPC API working correctly

curl http://localhost:7777/v1/chain/get_info

You can also check this in your Browser provide by chain_api_plugin

http://localhost:7777/v1/chain/get_info

3.8) Aliasing Cleos

We don’t need to enter in dockers container bash every time we interact with keosd so a solution for this we can alias it

alias cleos=’docker exec -it eosio /opt/eosio/bin/cleos — url http://127.0.0.1:7777 — wallet-url http://127.0.0.1:5555'

Execute this command in your terminal or add this to your .bashrc file , you can find .bashrc file at home it may be a hidden file , use shortcut cntrl + h to show hidden files.

4. Contract Development Toolkit(Install CDT)

CDT for short, is a collection of tools related to contract compilation, use CDT primarily for compiling contracts and generating ABIs.

Install Command :

Wget https://github.com/eosio/eosio.cdt/releases/download/v1.3.2/eosio.cdt-1.3.2.x86_64-0.x86_64 .rpm
sudo yum install ./eosio.cdt-1.3.2.x86_64–0.x86_64.rpm

Copy this command and execute in your terminal you will get the following result

Beginner’s Guide to EOS and Basic Smart Contracts 6

Till now you have successfully setup the environment and installed Contract development toolkit. Now you will going setup wallet and account that really very interesting part of EOS

blockchain .

5. Create Development Wallet

5.1) create a wallet

To create a wallet you need to enter in a docker container bash by using the following command

Command :

sudo docker exec -it eosio bash

After that enter wallet creation command

cleos wallet create — to-console

 

— to — console is used because we are using only for development purpose not production for production use — to — file as it will return your wallet private.

Wallets are closed by default

Command :

 

Cleos wallet open
Cleos wallet list

Beginner’s Guide to EOS and Basic Smart Contracts 7

If you will get the following result then your wallet is created and opened successfully.

By default your cleos wallet is locked you need to unlock it by using the command : cleos wallet unlock, you can see the difference between locked and unlocked wallet when you execute a command cleos wallet list it will return default for now without asterisk when it is locked, after

executing unlock command you can see the asterisk sign which shows now wallet is unlocked.

Beginner’s Guide to EOS and Basic Smart Contracts 8

Now we have to import the key in the wallet

cleos wallet create_key

Result: Created a new private key with a public key of: “EOS8PEJ…GDJQY5Y”

By executing this command you will get the public key as shown below copy that key.

5.2) Import Development Key

cleos wallet import

Now enter eosio development key provided below:

5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

Beginner’s Guide to EOS and Basic Smart Contracts 9

The default wallet is now unlocked and a key has been loaded. You are ready to proceed.

Use case: Deploy, Issue and transfer Tokens

We are implementing a token contract to issue token and transfer to any account/user.

Source Code is available at EOSIO’S GitHub:

Command :

git clone https://github.com/EOSIO/eosio.contracts — branch v1.4.0 — single-branch

Make sure you are in the eosio contract directory:

cd eosio.contracts/eosio.token

 

6) Create Account

An account is a collection of authorizations, stored on the blockchain, and used to identify a sender/recipient.

cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

 

Beginner’s Guide to EOS and Basic Smart Contracts 10

6.1) Compile Contract

eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp — abigen

 

Beginner’s Guide to EOS and Basic Smart Contracts 11

6.2) Deploy Contract

cleos set contract eosio.token /home/abhi_21094/Desktop/EOStest/eosio.contracts/eosio.token — abi eosio.token.abi -p eosio.token@active

6.3) Create Token

cleos push action eosio.token create ‘[ “eosio”, “1000000000.0000 SYS”]’ -p eosio.token@active

 

Beginner’s Guide to EOS and Basic Smart Contracts 12

6.4) Issue Token

cleos push action eosio.token create ‘{“issuer”:”eosio”, “maximum_supply”:”1000000000.0000 SYS”}’ -p eosio.token@active

 

Beginner’s Guide to EOS and Basic Smart Contracts 13

6.5) Transfer Tokens from one account to another account

cleos push action eosio.token transfer ‘[ “alice”, “bob”, “25.0000 SYS”, “m” ]’ -p alice@active

 

Beginner’s Guide to EOS and Basic Smart Contracts 14
6.6) Return a Transaction in JSON

cleos push action eosio.token issue ‘[“alice”, “100.0000 SYS”, “memo”]’ -p eosio@active -d -j

Beginner’s Guide to EOS and Basic Smart Contracts 15

6.7) To check the balance of any account using the account name

cleos get currency balance eosio.token bob SYS
25.00 SYS
cleos get currency balance eosio.token alice SYS
75.00 SYS

 

Beginner’s Guide to EOS and Basic Smart Contracts 16

Well Done You have successfully Set Up Environment, Created Wallet, Accounts, compiled and Deployed Smart Contract of Token on EOSIO Blockchain.

We’re available for EOS smart contract development and security auditing work. You can fill this form https://quillhash.typeform.com/to/KQ5Hhm to get in touch.

Thanks for reading. Also, do check out our earlier blog posts.

Get The Latest Research And Case Studies On Blockchain Technology Delivered Directly In Your Inbox. 

JOIN OUR NEWSLETTER