Last year was really epic for the blockchain startups. Thanks to the Ethereum Blockchain and the opportunities it gave to the developers to create decentralized applications a lot of blockchain companies had been born.
Ethereum started the spark of the blockchain development when it introduced the Solidity language and the Smart Contracts – the building blocks for decentralized applications. However, Ethereum was just the beginning. The blockchain technology is developing at a rapid pace and now a new and most powerful one is on the way. It’s time to introduce the EOS Blockchain.
EOS is aiming to become the first decentralized operating system which can support industrial-scale decentralized applications. It introduces a new blockchain architecture designed to enable vertical and horizontal scaling of dApps. It’s achieved by creating an operating system-like construct upon which applications can be built.
The EOSIO software provides accounts, authentication, databases, asynchronous communication, and the scheduling of applications across many of CPU cores or clusters. The resulting technology is a blockchain architecture that may ultimately scale to millions of transactions per second, eliminates user fees, and allows for quick and easy deployment and maintenance of decentralized applications, in the context of a governed blockchain.
Surely, EOS set the level very high compared to its siblings!
EOS Blockchain Development
In order to help the EOS Blockchain Development community, our development team at Infinite X Labs decided to run a number of tutorials dedicated to EOS Development. In this tutorial, we’ll explore the steps which will help you to set up your environment and run your first testnet node. We will create an account and we will deploy a sample smart contract to the EOS Blockchain so we can interact with it.
Keep a note that the EOSIO is still in development and some of the steps might change in the future. However, our team will try to keep the tutorial always up to date
Last update – 25 November, 2018 – The tutorial was updated with the latest version of EOSIO – v1.4.4
So, let’s start!
1. Setting up a build/development environment
In order to build EOS dApps, we need first to set up our environment. When you’re building your dApps most of the time you will use the testnet. EOS give us the choice between building for a local testnet or for the public testnet. Аt the time of writing this tutorial the public testnet is currently unavailable, so we will use the local testnet.
For the purpose of the tutorial, we are going to use macOS Mojave version 10.14
Setting up the environment is really easy thanks to the automated build script by EOSIO. It installs all dependencies and builds EOSIO. Before running the script, as a first step, clone the EOS repo recursively with the following command:
Once this is done go to the eos folder and run the eosio_build.sh script with the following command:
It could take quite some time before all the dependencies are installed and then built.
If you finally see this screen then congratulations! You have successfully installed all dependencies and built EOSIO. It is good to verify your installation, but we will do that in a while. Before that let’s check what the installation has generated.
When the EOSIO was built it created lots of files and folders. Let’s take a look at some of them.
The programs folder – /eos/programs
The program’s folder contains some very helpful programs from EOSIO
- nodeos – server-side blockchain node component. The core EOSIO daemon that can be configured with plugins to run a node. Example uses are block production, dedicated API endpoints, and local development.
- cleos – command line interface to interact with the blockchain
- keosd – an EOSIO wallet daemon that loads wallet related plugins, such as the HTTP interface and RPC API
- eosio-launcher – application to assist with deploying a multi-node blockchain network
The build folder – /eos/build
The build folder is where all the built content goes. You can find the executables of eos/programs folder in subfolders within the eos/build/programs.
The build folder is where we’re going to make our build validation. It’s a set of tests that can be run against your build to perform some basic validation. To run the test suite after building we need to start the mongo daemon and then run make test command.
Note: In order to run the command you must be inside the build folder
If all has gone well, all of the tests should pass. If you see more than 24 tests don’t be surprised. EOSIO constantly add new tests with every release 🙂
Now it’s time to install the executables. For ease of contract development, content can be installed in the /urs/local folder using the make install command. This step is run from the build folder. Adequate permission is required to install.
2. Creating and Launching a Single Node Testnet
It finally comes the time to launch our first testnet node.
With the latest version of EOSIO you can start your own single-node blockchain with the following command:
If you’re getting an error “nodeos”: command not found, you should add the new binaries path to the PATH environment variable. Check for more info the issue at GitHub
It will start generating blocks. Awesome!
If the terminal window was closed and you want to start your node again just run the command above. It will start producing blocks from your latest one.
Also when you ran the command the first time a few folders were created at the path ~/Library/Application Support/eosio/ – There you can find some of the files we will talk about in the next couple of lines.
But first, you probably wonder what all these parameters are in the command, so let’s take a look
1. Main command
2. Config Options for eosio::producer_plugin
-e - Enable block production, even if the chain is stale
-p <producer_name> - ID of producer controlled by this node
3. Application Config Options
--plugin arg - Plugin(s) to enable, may be specified multiple times
With EOSIO Dawn 4.2 there are several command line options for eosio::chain_plugin which you can use:
3. Validate the Environment
Are you ready for some interesting stuff to do?
EOSIO comes with example contracts that can be uploaded and run for testing purposes. We will validate our single node setup using the eosio.token contract. It is assumed nodeos is running as described above.
Create a wallet
Every contract requires an associated account, so first, you need to create a wallet. To create a wallet, you need to have the wallet_api_plugin loaded into the nodeos process. This can be accomplished in one of two ways:
- Via a plugin entry in the config.ini file (i.e. plugin = eosio::wallet_api_plugin) in ~/Library/Application Support/eosio/nodeos/config folder
- Via a plugin command-line option when invoking nodeos (i.e. –plugin eosio::wallet_api_plugin)
Use the wallet create subcommand of cleos to create a wallet.
Import the Private Key for eosio Account
Note: You should only use it for testing purposes
The key can be found in the config.ini file which is located in ~/Library/Application Support/eosio/nodeos/config.
Once you get the key you need to import it to the wallet:
Create an account for the “eosio.token” contract
The account named “token” will be used for the “eosio.token” contract. Generate two public/private key pairs that will be later assigned as the public-OwnerKey and the public-ActiveKey.
This will output two pairs of public and private keys of the form:
Private key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Public key: EOSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Import the two private keys into the wallet.
Note: If you don’t specify the name of the wallet, the “default” one will be used. Also, don’t forget to save your generated keys.
Create the token account using the cleos create account command. The create will be authorized by the eosio account. The two public keys generated above will be associated with the account, one as its OwnerKey and the other as its ActiveKey. You should get a JSON response back with a transaction ID confirming it was executed successfully.
If you see “warning: transaction executed locally, but may not be confirmed by the network yet” don’t worry. The transaction executed locally warning is normal and applies to all transactions. Successfully submitting a transaction is no guarantee the transaction will be executed. If the block producers are heavily loaded at the time, the transaction may be dropped.
Verify that the account was successfully created with the following command:
and if all has gone well, you will receive an output similar to the following:
Upload the “eosio.token” contract to the blockchain
Upload the contract using the token account. The response should be a transaction_id with some JSON. This indicates your contract was successfully uploaded:
You can also verify that the code has been set with the following command:
Before using the eosio.token contract, you must first create and then issue the tokens.
Next, verify the initial balance:
Transfer funds using the “eosio.token” contract
The following command shows a “transfer” action being sent to the eosio.token contract, transferring “20.0000 TKN” from the “token” account to the “eosio” account. A successfully submitted transaction will generate a transaction ID and JSON output similar to the following.
Check the balances
Check the state of both accounts involved in the previous transaction as follows:
the receiving account eosio now has a balance of 20 TKN, and the sending account token now has 20 TKN less than its initial issue.
Let’s summarize all the steps so far. We first installed EOSIO and we set up our development environment. We installed the executables needed for contract development and we have started our first testnet node which generates blocks on the blockchain. We learned how to generate public/private keys and import them into our wallet. We created an account using our public keys – OwnerKey & ActiveKey and we deployed the eosio.token contract. As a finale, we transferred funds using the eosio.token contract between the accounts.
Want to learn more? Check the next part of the EOS Blockchain Development series here