This is my first of many tutorials on EOSIO smart contract development. In hope to help grow eos ecosystem I’ll try to share as many tips, tricks and examples as I can.

Tutorial 1

Requirements:

– Linux OS

– ( with little work should work on Mac and Windows )

– Visual Studio Code

– ( enabled IntelliSense )

– cmake

– clang 4.0 lldb-4.0

– python3

I will not go trough installation and basics of using cleos and nodeos, which you can check here, rather I’ll cover basics of writing scripts and show development setup example.

There are couple of ways to script eosio block-chain. It is needed for development and testing purposes. Most basic way to script would be to write bash scripts, but there are already libraries like

EOS.IO Go API library

and there is

EOSFactory  which is Python-based EOS smart-contract development & unit testing framework.

In real world scenario it’s much better to use something like eos-bios for security reasons.

We’ll use EOSFactory because it is cross platform and it’s python based.

https://github.com/gitgyver/eos-contracts is my git repository:

If you want to build environment from scratch, I forked eos and eosfactory from tokenika and added my forks via git submodule add.

File structure looks like this:

contracts
eos
eosfactory
templates  <- shortcut to eosfactory/templates

Clone

git clone https://github.com/gitgyver/eos-contracts –recursive

Install

sudo ./install.sh

Install script will automatically create genesis file and start first (required) nodeos run.

After nodeos starts prducing blocks press Ctrl + C to stop nodeos to continue install.sh

Test EOSFactory

cd eosfactory

source ~/.profile

python3 ./tests/unittest1.py

python3 ./tests/unittest2.py

python3 ./tests/unittest3.py

cd ..

In eosfactory/templates are template contracts. We can now generate new projects from templates like this.

cd contracts

python3 generate.py hello.world hello

How to use generate.py

python3 generate.py -name -template

Check project structure in eos-contracts/contracts/hello.world

.vscode

 

build
src <- contract files
test
CmakeLists.txt
script.py

There are several ways you can build your contracts

Visual Studio Code will automatically build contract by opening your contract folder. You can rebuild it by pressing Ctrl + Shift + B.

You can check eosfactory documentation here

Word of advice. When building contract with EOSFactory, for example like this

contract = eosf.Contract(john, “eosio.token”)

contract.build()

contract.deploy()

If you use above code and if you haven’t generated eosio.token contract it will look for it in eos-contracts/eos/build/contracts/eosio.token

I found bug which deletes contents of abi file in eos-contracts/eos/build/contracts/eosio.token when you do contract.build(), so you don’t have to build every contract you deploy

To run script locate to eos-contracts/contracts/hello.world and

source ~/.profile

python3 script.py

To run without exit use

python3 -i script.py

 

Hope you find it useful 🙂

13 votes, average: 4.77 out of 513 votes, average: 4.77 out of 513 votes, average: 4.77 out of 513 votes, average: 4.77 out of 513 votes, average: 4.77 out of 5 (13 votes, average: 4.77 out of 5)
You need to be a registered member to rate this.
(558 total tokens earned)
Loading...

Responses