Skip to main content

EOSIO Blockchain dApp Step by Step: Part 1 - Setup


After I listen Bettina Warburg’s speech, I am fascinated by the concept of decentralized economy (dApps). The traditional web application is:
Front End → Backend → Database

In contrast, dApp website is:
Front End → Smart Contract → Blockchain

For instance, when you go onto e-banking, the web page will call the backend code to grab your personal data and display them on the page. The backend code is running on centralized servers. As opposed to traditional, where dApps have their backend code (smart contract) running on a decentralized P2P network (Blockchain).

Why Is Blockchain So Hot?

"Blockchain is the technology that underpins the digital currency Bitcoin – but it has far wider applications and is being commercialised in a growing number of areas. It has generated much interest in technology circles and beyond, because of the new possibilities it opens up in financial services, the public sector and other areas."
THOUGHT LEADERSHIP Nov 2017

What Is EOSIO blockchain?

EOSIO advertised as an “operating system” for dApps. It is being built from the ground up to perform millions of transactions per second (compares with the current largest Blockchain network: Ethereum is only 15 transactions per second), making it more suitable for a complex dapp ecosystem and decentralized, tokenized economy.

What does this blog cover?

In this blog, I’m going to show you how I setup the EOSIO blockchain and develop the Smart Contract. This is part 1 of this series. Below demonstrates the EOSIO installation step-by-step with screenshots description. And how I setup the wallet, accounts, and tokens. Let’s get started.

A Clean Virtual Machine

To avoid conflict with existing software, I’ve prepared a clean virtual machine for this experiment. I’m using Linux KVM virtualization infrastructure (KVM is much faster than Virtualbox, it delivers only 2 percent worse than bare metal). I’ve allocated below config for the VM:
  • 8 GB RAM, 4 vCPU
  • 30 GB disk space
  • Ubuntu 17.10 desktop

1. Download the EOSIO

When the OS is installed, then I performed below actions in Terminal:

If you’d like to do the same thing, you can copy & paste the below commands to your Terminal:
$ sudo apt install git-core
$ git clone https://github.com/EOSIO/eos --recursive
$ cd eos
$ git submodule update --init --recursive
$ ./eosio_build.sh
$ export PATH=${HOME}/opt/mongodb/bin:$PATH
$ ~/opt/mongodb/bin/mongod -f ~/opt/mongodb/mongod.conf &
$ cd ~/eos/build: make test
$ sudo make install

2. Start the Servers

The EOSIO is installed at this point, I typed below commands to start the servers:

If you’d like to do the same thing, you can copy & paste the below commands to your Terminal:
$ cd ~/eos/build/programs/keosd
$ keosd --http-server-address=localhost:8899
# Open a new tab in Terminal
$ cd ~/eos/build/programs/nodeos
$ nodeos -e -p eosio --contracts-console --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::wallet_api_plugin
# Open a new tab in Terminal
$ alias cleos='~/eos/build/programs/cleos/cleos --wallet-url=http://localhost:8899'

3. Create Wallet, Keypairs, Accounts and Tokens

To store information in Blockchain, we need an account for identifier the data and the wallet to protect the keys for signing a transaction. Refer here for EOSIO Accounts and Wallets Conceptual Overview

I performed the below actions:

If you’d like to do the same thing, you can copy & paste the below commands to your Terminal (make sure the keosd & nodeos are running):
$ cd ~/eos
$ cleos wallet create
# Record the password
$ cleos wallet key
# Record the private & public key values
$ cleos wallet key
# Record the private & public key values
$ cleos wallet import ${private_key_1}
$ cleos wallet import ${private_key_2}
$ cleos wallet keys
# You should see two keys shown
$ cleos create account eosio myaccount ${public_key_1} ${public_key_2}
# You should see an error message as shown in slide 5
$ find ~ -name config.ini # The config.ini may locates at another directory in other platforms
$ nano ~/.local/share/eosio/nodes/config/config.ini
# Copy & paste the signature-provider's private key, as shown in slide 8
$ cleos wallet import ${private_key_signature-provider}
$ cleos wallet keys
# You should see three keys shown
$ cleos create account eosio myaccount ${public_key_1} ${public_key_2}
# The account should be created successfully as shown in slide 11
$ cleos create account eosio user ${public_key_1} ${public_key_2}
$ cleos create account eosio tester ${public_key_1} ${public_key_2}
$ cleos create account eosio eosio.token ${public_key_1} ${public_key_2}
$ cleos set contract eosio.token ~/eos/build/contracts/eosio.token -p eosio.token
$ cleos push action eosio.token create '{"issuer":"eosio", "maximum_supply":"1000000000.0000 SYS"}' -p eosio.token
$ cleos create account eosio user ${public_key_1} ${public_key_2}
$ cleos push action eosio.token issue '[ "user", "100.0000 SYS", "memo" ]' -p eosio
$ cleos push action eosio.token transfer '[ "user", "tester", "1.0000 SYS", "m" ]' -p user
$ cleos create account eosio exchange ${public_key_1} ${public_key_2}
$ cleos set contract exchange ~/eos/build/contracts/exchange -p exchange
$ cleos create account eosio eosio.msig ${public_key_1} ${public_key_2}
$ cleos set contract eosio.msig ~/eos/build/contracts/eosio.msig -p eosio.msig
$ mkdir backup-my-wallet
$ cp -R ~/eosio-wallet ./backup-my-wallet/

4. Try compiling a smart contract: hello

EOSIO Smart Contract is a C++ program executes in blockchain. Refer here for the docs.

EOSIO provides several sample contracts in contracts/ directory. I took the hello contract for testing as below:

If you’d like to do the same thing, you can copy & paste the below commands to your Terminal (make sure the keosd & nodeos are running):
$ cd ~/eos/contracts/hello
$ eosiocpp -o hello.wast hello.cpp
$ eosiocpp -g hello.abi hello.cpp
$ cleos create account eosio hello.code ${public_key_1} ${public_key_2}
$ cleos set contract hello.code ../hello -p hello.code
$ cleos push action hello.code hi '["user"]' -p user
# Modify the hello.cpp as shown in slide 8
$ eosiocpp -o hello.wast hello.cpp
$ cleos set contract hello.code ../hello -p hello.code
$ cleos push action hello.code hi '["tester"]' -p user
# You should see an Error message as shown in slide 9
$ cleos push action hello.code hi '["tester"]' -p tester
# It should be no error
$ pkill keosd && pkill nodeos

What’s Next

In part 2, I will step-by-step show you how to develop a smart contract that illustrates the power of EOSIO blockchain.

Comments

  1. Enjoy the marvel of mathematics by exploring multiplication information of 7 . Have your individual math-themed party by learning how to to|tips on how to} multiply by 5 utilizing array models. Lush Eastern influences creates a soothing, zen-filled hideaway where find a way to|you probably can} enjoy gaming within the quiet calm. Come to work at some of the thrilling and dynamic organizations within the state of Oklahoma. The job possibilities are as wide-ranging as they're life-changing at Riverwind. We’re completely crazy about Crazy four Poker at Riverwind Casino and we know might be} too, whenever you step a lot as} a 먹튀사이트 먹튀프렌즈 table.

    ReplyDelete

Post a Comment

Popular posts from this blog

Create An Online Store Theme Used By MyCMS

MyCMS is an open-source Content Management System to generate static online shop website. You can use my hosting to input your products, or you can download the source codes and host it in your own server (running NodeJS). Please refer to my Github repo for the detailed installation instructions. This blog is a step-by-step tutorial that shows you how to create an online-shop theme. In this tutorial, it’s using my hosting to input the shop details and products. If you’re hosting the MyCMS by yourself, just change the domain name to yours will do. Introducing MyCMS Before making the theme, you’ll need to use MyCMS to configure the demo shop and input two demo products. MyCMS generates a static website via a theme. The generated static website is NO server program required. You can put the website files (HTML/CSS/JS) to any CDN, hosting. Shop Configuration You must prepare below settings Before using MyCMS: Setting Description Example Store name Your store name will be displayed in t...

How I make a web-components based dynamic Javascript page at the top of Google Search

Introduction Everybody wants their website shown at the first position of Google search. SEO (Search Engine Optimization) is a big topic. I just helped my client's website shows the database records at the top search rankings (at least several Chinese generic keywords). See the three example questions all are listed at top ranking: Website background: My client's website  popa.qa  is a traditional Chinese Q&A site that lets members ask and answer questions. All answers and questions are storing in the database server. Step 1: Create The Project This blog illustrates the problems and the steps to fix that with project source codes. Below is the description of the basic project: NodeJS backend (server.js) Develop an API ( /get-database-records ) to simulate getting database records Web-components frontend (index.html) An example component IndexPage  make use of  LitElement to render database records To start the server type: npm start Then I check the webpag...

Build A Simple Sales System using Google Drive

Google Drive is a free-to-use cloud service with a 15 GB limit storage. 15 GB is large enough to store documents, and "program" too. Yes, it's correct. We can program Google Drive. This blog is a step-by-step tutorial to show you how to build a simple P.O.S. system on Google Drive. Create a Google Sheets to define the products 1. Login to Google Drive using your Gmail account and create a Google Sheets: 2. Input the products in the Google Sheets Create a Google Forms for sale input 1. Create a new Google Form 2. Edit the form and the first field Note that leave the option field unchanged. We'll assign it programmatically in below 3. Add a quantity field 4.  Add a last field for the price input How to copy data from Google Sheets to Google Forms? We need to add a script to do that. Google developed Google App Script (GAS) for us to achieve that. Now go back to the Google Sheet we just created above. Then enter to the script editor You'll see the below screen. Then ...