This is a beginner’s guide, to setup a simple development environment for the EOSIO blockchain, which will get you up and running in five simple steps from zero to your first smart contract in less than 10 minutes. Afterwards, you will know how to code and test your own smart contracts on an EOS testnet quickly and for free. In this guide we make use of simple tools, which offer a great developer experience, such as the eosio.cdt (Contract Development Toolkit), the Kylin testnet and the eosc command line wallet. We’re using a development machine, running the Ubuntu 18.04 operating system.
So let’s get started!
1. Account, Keys and Tokens
The Kylin Testnet, which is run by several high class block producers, allows easy and fast access to a (non-productive) EOSIO blockchain, using it’s free Account and Faucet services. We’re going to create a new EOS account (12 character name) on the testnet, including @owner and @active keypairs and charge it up with 100 dummy EOS tokens.
Let’s call our new EOS account: dummyaccount
curl http://faucet.cryptokylin.io/create_account?dummyaccount
{
"msg": "succeeded",
"keys": {
"active_key": {
"public": "EOS7kNBssiunoW7VGcx79BXGUvjbgcaPva4azRwhuTXRfJJ192DJ2",
"private": "5J1SYvRP1JpWBtk85a4zAbXUmAyBqtr3r58hLuDF5YX6HdcfTYo"
},
"owner_key": {
"public": "EOS6nUXrdodNwRspd7Z42Yp8nRH44wuJNYYoVHSMddr28KKS6Ke4J",
"private": "5KQzVMR9sZ8sRmRb3NQEzyW43peUow6pYLo831AAXGyEZP7h77z"
}
},
"account": "dummyaccount"
}
curl http://faucet.cryptokylin.io/get_token?dummyaccount
{ "msg": "succeeded" }
Save your @owner and @active keypairs somewhere safe, you’ll need them for the next steps.
2. Wallet and CLI
Next we will download and install the eosc command line wallet, by EOS Canada, in order to interact with the EOS blockchain (currently v1.1.0). This will help us to safely store our private keys and send transactions to the blockchain.
mkdir eosc && cd eosc
curl -LO https://github.com/eoscanada/eosc/releases/download/v1.1.0/eosc_1.1.0_linux_x86_64.tar.gz
tar xzvf ./eosc_1.1.0_linux_x86_64.tar.gz
Now we can use it to import our EOS account via the @active key. This will create a file, named eosc-vault.json, which will contain your encrypted private key.
./eosc vault create --import
- Paste your @active private key from above.
5J1SYvRP1JpWBtk85a4zAbXUmAyBqtr3r58hLuDF5YX6HdcfTYo
- Hit ENTER.
- Choose a passphrase
3. Account Setup
Here we will issue three ./eosc commands, to setup our account for the deployment of a smart contract. We delegate 20 EOS tokens as blockchain resources (5 EOS staked for NET, 15 EOS staked for CPU) and use some more EOS tokens to buy 500 KiB of RAM as storage for our smart contract. Finally, we check our account with the eosc get account
command.
Hint: We need approximately 10x the bytes of RAM as is the filesize of our WASM binary contract, due to the overhead of the virtual machine. So if our compiled contract file (e.g. hello.wasm) has a filesize of 10 KiB, we need approximately 100 KiB in RAM resources on the EOSIO blockchain, to deploy the contract.
./eosc -u https://kylin.eoscanada.com system delegatebw dummyaccount dummyaccount 5 15
./eosc -u https://kylin.eoscanada.com system buyrambytes dummyaccount dummyaccount 512000
./eosc -u https://kylin.eoscanada.com get account dummyaccount
privileged: false
created at: 2018-11-15 14:45:25 +0000 UTC
permissions:
"owner" w/1 : +1 EOS6nUXrdodNwRspd7Z42Yp8nRH44wuJNYYoVHSMddr28KKS6Ke4J
"active" w/1 : +1 EOS7kNBssiunoW7VGcx79BXGUvjbgcaPva4azRwhuTXRfJJ192DJ2
memory:
quota: 506.8 KB used: 3.490 KB
net bandwidth:
staked: 5.0000 EOS (total stake delegated from account to self)
delegated: 1.0000 EOS (total stake delegated to account from others)
used: 257 bytes
available: 11.18 MB
limit: 11.18 MB
cpu bandwidth:
staked: 15.0000 EOS (total stake delegated from account to self)
delegated: 1.0000 EOS (total stake delegated to account from others)
used: 1.129 ms
available: 807.2 ms
limit: 808.3 ms
EOS balances:
liquid: 67.8553 EOS
staked: 20.0000 EOS
unstaking: 0.0000 EOS
total: 87.8553 EOS
voted for:
voter info:
proxy:
is proxy: false
staked: 200000
vote weight: 0.000000
proxied vote weight: 0.000000
4. Contract Development Toolkit
Download and install the latest version of eosio.cdt (currently v1.4.1). This will give you access to the smart contract WASM and ABI compilers/generators, as well as to the eosio C/C++ libraries and header files. Get it at: https://github.com/EOSIO/eosio.cdt/releases
curl -LO https://github.com/EOSIO/eosio.cdt/releases/download/v1.4.1/eosio.cdt-1.4.1.x86_64.deb
sudo dpkg -i ./eosio.cdt-1.4.1.x86_64.deb
5. Compile and Deploy a Smart Contract
Let’s create a simple “Hello World” smart contract, by creating a file with the following contents, named hello.cpp:
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
CONTRACT hello : public contract {
public:
using contract::contract;
ACTION hi( name user ) {
print( "Hello, ", name{user});
}
ACTION yo( name user ) {
print( "Yo, ", name{user});
}
};
EOSIO_DISPATCH( hello, (hi)(yo) )
This C++ file can now be compiled and deployed to the EOS blockchain, using the eosio.cdt Contract Development Toolkit. After compilation we will get a binary WASM file hello.wasm of about 2.3 KiB (needs ~23 KiB of eosio RAM) and a file named hello.abi, which describes the interface of our code’s actions.
eosio-cpp -o hello.wasm hello.cpp --abigen
./eosc -u https://kylin.eoscanada.com system setcontract dummyaccount ./hello.wasm ./hello.abi
./eosc -u https://kylin.eoscanada.com tx create dummyaccount yo '{"user":"bob"}' -p dummyaccount
Congratulations!
After finishing the five simple steps above, you can now officially call yourself a “Blockchain Expert”. 😉
Feel free to experiment with the above mentioned tools, keep on improving your EOSIO knowledge with help of the hyperlinks I put into the article and continue to develop you very own EOS smart contracts!
If you liked this tutorial, please consider a donation to my EOS account: teammaerdian