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.
– Linux OS
– ( with little work should work on Mac and Windows )
– Visual Studio Code
– ( enabled IntelliSense )
– clang 4.0 lldb-4.0
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
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:
File structure looks like this:
|templates <- shortcut to eosfactory/templates|
git clone https://github.com/gitgyver/eos-contracts –recursive
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
In eosfactory/templates are template contracts. We can now generate new projects from templates like this.
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
|src <- contract files|
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”)
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
To run without exit use
python3 -i script.py
Hope you find it useful 🙂