Table of Contents
Overview
In this lab, you will create a virtual machine (VM) to host an EOSIO blockchain single node. You will load and start a local single node blockchain, create a wallet, and load the eosio private key. This is an EOSIO Fundamentals lab.
Objectives
In this lab, you will learn how to perform the following tasks:
Create a Compute Engine virtual machine
Install the EOSIO platform
Run a single node blockchain
Create a wallet
Load the EOSIO private key
Install the EOSIO Contract Development Toolkit (CDT)
Create a blockchain account
Prerequisites
Before you start this lab, make sure you get familiar with the following:
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
- Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
How to start your lab and sign in to the Google Cloud console
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
The Open Google Cloud console button
Time remaining
The temporary credentials that you must use for this lab
Other information, if needed, to step through this lab
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account.
If necessary, copy the Username below and paste it into the Sign in dialog.
"Username"
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
"Password"
You can also find the Password in the Lab Details pane.
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
Note: Using your own Google Cloud account for this lab may incur extra charges.
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.
Background
This section provides an overview of the EOSIO concepts covered in this lab.
EOSIO Blockchain
An EOSIO blockchain is a highly efficient, deterministic, distributed state machine that can operate in a decentralized fashion. The blockchain keeps track of transactions within a sequence of interchanged blocks.
Each block cryptographically commits to the previous blocks along the same chain. It is therefore intractable to modify a transaction recorded on a given block without breaking the cryptographic checks of successive blocks. This simple fact makes blockchain transactions immutable and secure. Block production and block validation are performed by special nodes called Block Producers.
EOSIO Consensus
Block validation presents a challenge among any group of distributed nodes. A consensus model must be in place to validate such blocks in a fault tolerant way within the decentralized system. Consensus is the way for such distributed nodes and users to agree upon the current state of the blockchain. Two of the most common consensus models used in blockchains are Proof of Work (PoW) and Proof of Stake (PoS). In Proof of Stake, nodes that own the largest stake or percentage of some asset have equivalent decision power.
One interesting variant is Delegated Proof-of-Stake (DPoS) in which a large number of participants or stakeholders elect a smaller number of delegates, which in turn make decisions for them. EOSIO uses Delegated Proof of Stake (DPoS) to elect the active producers who will then be authorized to produce blocks, validate them, and sign them to eventually be added to the blockchain.
EOSIO Accounts, Keys, and Permissions
An account identifies a participant in an EOSIO blockchain. A participant can be an individual or a group depending on the assigned permissions within the account. Accounts also represent the smart contract actors that push and receive actions to and from other accounts in the blockchain. Keys in EOSIO are binary strings represented in Base58 used for signing and verification of transactions, blocks, and other messages. Keys are created within a digital wallet associated with an account.
Since account ownership is defined solely by the account name, the keys associated with an account can be updated without compromising security. A novel permission scheme involving accounts, permissions, and authority tables determine what accounts can do and how the actions that make a transaction are authorized. To that end, each account is assigned a hierarchical permission structure and each permission is assigned a pair of public and private keys used for signing and verification.
Task 1. Create a virtual machine using the Google Cloud Console
In the Navigation Menu (), click Compute Engine > VM instances.
To create a new instance, click Create Instance.
In the Machine configuration.
Select the following values:
Name:
my-vm-1
Region:
us-east1
Zone:
us-east1-d
Machine Family:
General Purpose
Series:
E2
Machine Type:
e2-standard-2
Click OS and storage.
For Boot disk, if the Image shown is not Ubuntu 20.04 LTS, Click Change to begin configuring your boot disk and select the following values:
Operating system:
Ubuntu
Version:
Ubuntu 20.04 LTS
Leave the size as default and Click on Select.
Click Security.
Leave the defaults for Identity and API access and all other fields unmodified.
Click Create.
Note: The VM can take about two minutes to launch and be fully available for use.
Click Check my progress to verify the objective.
Create a virtual machine using the Google Cloud Console
Check my progress
Task 2. Install the EOSIO platform
In the Navigation Menu , click Compute Engine > VM instances. You will see the VM instance you created.
Click the SSH button next to the
my-vm-1
instance.Update the libraries on your OS by running:
sudo apt update
- At the command prompt on
my-vm-1
, run the following to get the eosio binaries:
curl -LO https://github.com/eosio/eos/releases/download/v2.1.0/eosio_2.1.0-1-ubuntu-20.04_amd64.deb
- Next, run the following to install the EOSIO platform:
sudo apt install ./eosio_2.1.0-1-ubuntu-20.04_amd64.deb
- Confirm
nodeos
is installed:
nodeos --version
The response will be the nodeos
version:
v2.1.0
- Confirm
cleos
is installed:
cleos version client
The response will be the cleos
version:
v2.1.0
- Confirm
keosd
is installed:
keosd -v
The response will be the keosd
version:
v2.1.0
Click Check my progress to verify the objective.
Install the EOSIO platform
Check my progress
Task 3. Run a local single node blockchain
- At the command prompt on
my-vm-1
, start thenodeos
service daemon as a background task and launch a single node blockchain, directing the console output to a nodeos.log file:
nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --contracts-console >> nodeos.log 2>&1 &
The response will be the PID for nodeos.
- Verify that nodeos is running and producing blocks:
tail -f nodeos.log
The output will look like this:
info 2021-03-08T02:44:11.900 nodeos producer_plugin.cpp:2227 produce_block ] Produced block e0dc6324ce3c8f35... #588 @ 2021-03-08T02:44:12.000 signed by eosio [trxs: 0, lib: 587, confirmed: 0]
You will see the current block, and last irreversible block (lib) incrementing.
- Press Ctrl+C to exit tail.
Click Check my progress to verify the objective.
Run a local single node blockchain
Check my progress
Task 4. Create wallet
- At the command prompt on
my-vm-1
, create a wallet, named my_wallet, and output the wallet password to a file named my_wallet_password:
cleos wallet create --name my_wallet --file my_wallet_password
The response will show:
"/usr/opt/eosio/2.0.9/bin/keosd" launched
Creating wallet: my_wallet
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
saving password to wallet_password
- View the wallet password:
cat my_wallet_password
- To view the local wallets execute this command:
cleos wallet list
The response will be:
Wallets:
[
"my_wallet *"
]
Click Check my progress to verify the objective.
Create wallet
Check my progress
Task 5. Add the EOSIO system account private key to the new wallet
Every new EOSIO blockchain has a default system user called eosio. This account is used initially to set up the blockchain. It defaults to the private key, 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
. Import this private key to your wallet to sign transactions on behalf of the eosio user.
- At the command prompt on
my-vm-1
, use thecleos wallet open
command to open the my_wallet wallet:
cleos wallet open --name my_wallet
The response will be:
Opened: my_wallet
Copy the wallet password from the my_wallet_password file.
Use the
cleos wallet unlock
command to unlock the my_wallet wallet, add the wallet password in toYOUR_PASSWORD
:
cleos wallet unlock --name my_wallet --password YOUR_PASSWORD
The response will be:
Unlocked: my_wallet
- Use the
cleos wallet import
command to import the EOSIO private key,5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
, to the my_wallet wallet:
cleos wallet import --name my_wallet --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
The response will be:
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
Click Check my progress to verify the objective.
Add the eosio system account private key to the new wallet
Check my progress
Task 6. Install the EOSIO Contract Development Toolkit (CDT)
- At the command prompt on
my-vm-1
, run the following to get the eosio binaries:
curl -LO https://github.com/eosio/eosio.cdt/releases/download/v1.8.1/eosio.cdt_1.8.1-1-ubuntu-20.04_amd64.deb
- At the command prompt on
my-vm-1
, install the CDT:
sudo apt install ./eosio.cdt_1.8.1-1-ubuntu-20.04_amd64.deb
- Confirm the CDT is installed:
eosio-cpp --version
The response will be the CDT version:
eosio-cpp version 1.8.1
Click Check my progress to verify the objective.
Install the EOSIO Contract Development Toolkit (CDT)
Check my progress
Task 7. Create a blockchain account
- At the command prompt on
my-vm-1
, use thecleos wallet open
command to open the my_wallet wallet:
cleos wallet open --name my_wallet
The response will be:
Opened: my_wallet
- Copy the wallet password from the
my_wallet_password
file:
export wallet_password=$(cat my_wallet_password)
echo $wallet_password
- Use the
cleos wallet unlock
command to unlock the my_wallet wallet, using the$wallet_password
environment variable you just created:
cleos wallet unlock --name my_wallet --password $wallet_password
The response will be:
Unlocked: my_wallet
- Use the
cleos create key
command to create a public/private key pair to use with the blockchain account:
cleos create key --file my_keypair1
The response will be:
saving keys to my_keypair1
- Check the file
my_keypair1
:
cat my_keypair1
The response will be the generated public and private keys and will look like:
Private key: 5J4drLKDPL6zHKSeMDQPNoSTsnBfkue757bR7CUxM21vJfgb9oR
Public key: EOS7puQYu36qyTbgPvJRgRoTU88BCREiqQTANTLZA44hxsdtxT9bY
This shows YOUR_PRIVATE_KEY and YOUR_PUBLIC_KEY.
- Use the
cleos wallet import
command to import the eosio private key created in the previous step YOUR_PRIVATE_KEY, to the my_wallet wallet:
cleos wallet import --name my_wallet --private-key YOUR_PRIVATE_KEY
The response will be:
imported private key for: YOUR_PUBLIC_KEY
- Use the
cleos create account
command to create a blockchain account using YOUR_PUBLIC_KEY:
cleos create account eosio bob YOUR_PUBLIC_KEY
The response will be:
executed transaction: 6a2aab0f2960c062652884e16e95c5313828d4630725bb2427f81f0d3dfe8f85 200 bytes 299 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"bob","owner":{"threshold":1,"keys":[{"key":"EOS7puQYu36qyTbgPvJRgRoTU88BC...
warning: transaction executed locally, but may not be confirmed by the network yet
Click Check my progress to verify the objective.
Create a blockchain account
Check my progress
Solution of Lab
curl -LO raw.githubusercontent.com/Techcps/Google-Cloud-Skills-Boost/master/Blockone%20Getting%20Started%20with%20The%20EOSIO%20Blockchain/techcps873.sh
sudo chmod +x techcps873.sh
./techcps873.sh