# Block.one: Getting Started with The EOSIO Blockchain - GSP873

## 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:

* [EOSIO Platform and Toolchain](https://developers.eos.io/welcome/latest/introduction-to-eosio/platform_and_toolchain)
    
* [EOSIO Core Concepts](https://developers.eos.io/welcome/latest/introduction-to-eosio/core_concepts)
    
* [EOSIO Technical Features](https://developers.eos.io/welcome/latest/introduction-to-eosio/technical_features)
    

## 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

1. 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
        
2. 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**.
    
3. If necessary, copy the **Username** below and paste it into the **Sign in** dialog.
    
    ```apache
    "Username"
    ```
    
    You can also find the Username in the Lab Details pane.
    
4. Click **Next**.
    
5. Copy the **Password** below and paste it into the **Welcome** dialog.
    
    ```apache
    "Password"
    ```
    
    You can also find the Password in the Lab Details pane.
    
6. 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.
    
7. 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.

![Navigation menu icon and Search field](https://cdn.qwiklabs.com/9Fk8NYFp3quE9mF%2FilWF6%2FlXY9OUBi3UWtb2Ne4uXNU%3D align="left")

## 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

1. In the **Navigation Menu** (), click **Compute Engine** &gt; **VM instances**.
    
2. To create a new instance, click **Create Instance**.
    
3. 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`
        
4. 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**.
    
5. Click **Security**.
    
    Leave the defaults for **Identity and API access** and all other fields unmodified.
    
6. 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

1. In the **Navigation Menu** , click **Compute Engine** &gt; **VM instances**. You will see the VM instance you created.
    
2. Click the **SSH** button next to the `my-vm-1` instance.
    
3. Update the libraries on your OS by running:
    

```apache
sudo apt update
```

4. At the command prompt on `my-vm-1`, run the following to get the eosio binaries:
    

```apache
curl -LO https://github.com/eosio/eos/releases/download/v2.1.0/eosio_2.1.0-1-ubuntu-20.04_amd64.deb
```

4. Next, run the following to install the EOSIO platform:
    

```apache
sudo apt install ./eosio_2.1.0-1-ubuntu-20.04_amd64.deb
```

5. Confirm `nodeos` is installed:
    

```apache
nodeos --version
```

The response will be the `nodeos` version:

```apache
v2.1.0
```

6. Confirm `cleos` is installed:
    

```apache
cleos version client
```

The response will be the `cleos` version:

```apache
v2.1.0
```

7. Confirm `keosd` is installed:
    

```apache
keosd -v
```

The response will be the `keosd` version:

```apache
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

1. At the command prompt on `my-vm-1`, start the `nodeos` service daemon as a background task and launch a single node blockchain, directing the console output to a nodeos.log file:
    

```apache
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.

2. Verify that nodeos is running and producing blocks:
    

```apache
tail -f nodeos.log
```

The output will look like this:

```apache
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.

3. 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

1. 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**:
    

```apache
cleos wallet create --name my_wallet --file my_wallet_password
```

The response will show:

```apache
"/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
```

2. View the wallet password:
    

```apache
cat my_wallet_password
```

3. To view the local wallets execute this command:
    

```apache
cleos wallet list
```

The response will be:

```apache
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.

1. At the command prompt on `my-vm-1`, use the `cleos wallet open` command to open the **my\_wallet** wallet:
    

```apache
cleos wallet open --name my_wallet
```

The response will be:

```apache
Opened: my_wallet
```

2. Copy the wallet password from the **my\_wallet\_password** file.
    
3. Use the `cleos wallet unlock` command to unlock the **my\_wallet** wallet, add the wallet password in to `YOUR_PASSWORD`:
    

```apache
cleos wallet unlock --name my_wallet --password YOUR_PASSWORD
```

The response will be:

```apache
Unlocked: my_wallet
```

4. Use the `cleos wallet import` command to import the EOSIO private key, `5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3`, to the **my\_wallet** wallet:
    

```apache
cleos wallet import --name my_wallet --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
```

The response will be:

```apache
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)

1. At the command prompt on `my-vm-1`, run the following to get the eosio binaries:
    

```apache
curl -LO https://github.com/eosio/eosio.cdt/releases/download/v1.8.1/eosio.cdt_1.8.1-1-ubuntu-20.04_amd64.deb
```

2. At the command prompt on `my-vm-1`, install the CDT:
    

```apache
sudo apt install ./eosio.cdt_1.8.1-1-ubuntu-20.04_amd64.deb
```

3. Confirm the CDT is installed:
    

```apache
eosio-cpp --version
```

The response will be the CDT version:

```apache
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

1. At the command prompt on `my-vm-1`, use the `cleos wallet open` command to open the **my\_wallet** wallet:
    

```apache
cleos wallet open --name my_wallet
```

The response will be:

```apache
Opened: my_wallet
```

2. Copy the wallet password from the `my_wallet_password` file:
    

```apache
export wallet_password=$(cat my_wallet_password)
echo $wallet_password
```

3. Use the `cleos wallet unlock` command to unlock the **my\_wallet** wallet, using the `$wallet_password` environment variable you just created:
    

```apache
cleos wallet unlock --name my_wallet --password $wallet_password
```

The response will be:

```apache
Unlocked: my_wallet
```

4. Use the `cleos create key` command to create a public/private key pair to use with the blockchain account:
    

```apache
cleos create key --file my_keypair1
```

The response will be:

```apache
saving keys to my_keypair1
```

5. Check the file `my_keypair1`:
    

```apache
cat my_keypair1
```

The response will be the generated public and private keys and will look like:

```apache
Private key: 5J4drLKDPL6zHKSeMDQPNoSTsnBfkue757bR7CUxM21vJfgb9oR
Public key: EOS7puQYu36qyTbgPvJRgRoTU88BCREiqQTANTLZA44hxsdtxT9bY
```

This shows **YOUR\_PRIVATE\_KEY** and **YOUR\_PUBLIC\_KEY**.

6. 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:
    

```apache
cleos wallet import --name my_wallet --private-key YOUR_PRIVATE_KEY
```

The response will be:

```apache
imported private key for: YOUR_PUBLIC_KEY
```

7. Use the `cleos create account` command to create a blockchain account using **YOUR\_PUBLIC\_KEY**:
    

```apache
cleos create account eosio bob YOUR_PUBLIC_KEY
```

The response will be:

```apache
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

%[https://youtu.be/QieAOMw3I_8] 

```apache
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
```
