Mastering Ethereum Chapter 2

This is a summary of Mastering Ethereum Chapter 2 by Andreas M. Antonopoulos and Gavin Wood. As in their book and all my public posts, this content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Ethereum Basics

In this chapter we will start exploring Ethereum, learning how to use wallets, how to create transactions, and also how to run a basic smart contract.

Ether Currency Units

Ethereum’s currency unit is called ether, identified as “ETH” or with the symbols Ξ (from the Greek letter “Xi” that looks like a stylized capital E).

Ether is subdivided into smaller units, down to the smallest unit possible, which is named wei. One ether is 1 quintillion wei (1 * 1018 or 1,000,000,000,000,000,000). You may hear people refer to the currency “Ethereum” too, but this is a common beginner’s mistake. Ethereum is the system, ether is the currency.

The value of ether is always represented internally in Ethereum as an unsigned integer value denominated in wei. When you transact 1 ether, the transaction encodes 1000000000000000000 wei as the value.

Denominations

Value (in wei)ExponentCommon nameSI name
11weiWei
1,00010^3BabbageKilowei or femtoether
1,000,00010^6LovelaceMegawei or picoether
1,000,000,00010^9ShannonGigawei or nanoether
1,000,000,000,00010^12SzaboMicroether or micro
1,000,000,000,000,00010^15FinneyMilliether or milli
1,000,000,000,000,000,00010^18EtherEther
1,000,000,000,000,000,000,00010^21GrandKiloether
1,000,000,000,000,000,000,000,00010^24Megaether

Choosing an Ethereum Wallet

Wallet Definition

The term “wallet” has come to mean many things. We will use the term “wallet” to mean a software application that helps you manage your Ethereum account. In short, an Ethereum wallet is your gateway to the Ethereum system. It holds your keys and can create and broadcast transactions on your behalf. 

Choosing a Wallet

Choosing an Ethereum wallet can be difficult because there are many different options with different features and designs. Some are more suitable for beginners and some are more suitable for experts. Try different wallets to find one that suits your needs.

Control and Responsibility

Each user of Ethereum can — and should — control their own private keys. Private keys are used to gain control access to funds and smart contracts. So with control, comes responsibility. If you lose your private keys, you lose access to your account. No support team. No help desk. Nada.

Introducing the World Computer

Ether is meant to be used to pay for running smart contracts, which are computer programs that run on an emulated computer called the Ethereum Virtual Machine (EVM).

The EVM is a global singleton. While the Ethereum blockchain records the changing state of this world computer as it processes transactions and smart contracts.

Externally Owned Accounts (EOAs) and Contracts

Externally owned accounts are those that have a private key; having the private key means control over access to funds or contracts.

A contract account has smart contract code and does not have a private key. Instead, it is owned and controlled by the logic of its smart contract code: the software program recorded on the Ethereum blockchain at the contract account’s creation and executed by the EVM.

Like EOAs contracts have addresses and can send and receive ether. However, when a transaction destination is a contract address, it causes that contract to run in the EVM, using the transaction and its data as input.

Only EOAs can initiate transactions, but contracts can react to transactions by calling other contracts, building complex execution paths.

A Simple Contract: A Test Ether Faucet

// SPDX-License-Identifier: CC-BY-SA-4.0

// Version of Solidity compiler this program was written for
pragma solidity 0.6.4;

// Our first contract is a faucet!
contract Faucet {
    // Accept any incoming amount
    receive() external payable {}

    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public {
        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000);

        // Send the amount to the address that requested it
        msg.sender.transfer(withdraw_amount);
    }
}

You can compile, deploy, and interact with the ropsten test network using https://remix.ethereum.org/ and your metamask wallet.

1 comment

Comments are closed.