0% found this document useful (0 votes)
33 views10 pages

Ethereum - Blockchain 2.0

Fresco Ethereum - Blockchain fresco 2.0 slides
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views10 pages

Ethereum - Blockchain 2.0

Fresco Ethereum - Blockchain fresco 2.0 slides
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Ethereum - Blockchain 2.

Blockchain: Introduction
Whenever you listen to the term Blockchain the first word that pops up in your mind
is Bitcoin. So let's start the journey by knowing Bitcoin, Blockchain, and then
moving on to Ethereum.

What is Bitcoin?
Bitcoin is a digital cryptocurrency developed by a person/group of people known by
the pseudonym Satoshi Nakamoto. It was developed using Blockchain technology.

What is Blockchain?
Blockchain is a distributed database system that unlike the traditional systems, do
not store the data on a centrally controlled server. It is based on a peer-to-peer
network where every node has a copy of the data, and the data is secured through
encryption.

Now that you have a basic understanding of blockchain, let's start the journey to
Ethereum.

Ethereum: Introduction
Ethereum is a public, open source blockchain platform that is used to develop Smart
Contracts and Decentralized Application.
It was developed by Vitalik Buterin and Gavin Wood to exploit the existing
blockchain technology for more than just crypto-currency. It was also used for more
complex functionalities like writing contracts for transactions and developing
decentralized applications.
At its core, the Ethereum blockchain is similar to other public blockchain networks
like Bitcoin. It uses peer to peer connections and a modified version of Nakamoto
consensus mechanism to add blocks to the blockchain.

Ethereum: Introduction
It uses a modified version of Dagger Hashmito Proof of Work (PoW) algorithm called
the Ethash.

Ethereuem has its own cryptocurrency called the Ether, it also uses a token called
Gas for the execution of smart contracts.

It supports Turing complete programming language to build smart contracts.

Ethereum has Ethereum Virtual Machine (EVM) that runs on Ethereum nodes and is a
runtime environment to execute Smart Contracts.

Ethereum vs Bitcoin
Both Ethereum and Bitcoin are public blockchain networks but apart from that, they
have very few similarities both in terms of usage and the technologies implemented.

Bitcoin is a public blockchain platform used for a digital cryptocurrency, whereas


Ethereum is used for smart contracts-based transactions and developing DApps.
Bitcoin blockchain doesn't support Turing complete programming languages, but
Ethereum blockchain supports Turing complete languages.
In Ethereum, the time between blocks is around 14 seconds, compared with Bitcoin's
~10 minutes.
Bitcoin uses Dagger Hashmito algorithm for Proof of Work. Ethereum uses a modified
version of the Dagger Hashmito algorithm called Ethash.
Lastly, the founders of Bitcoin are unknown and are known by the pseudonym Satoshi
Nakamoto, Ethereum was developed by Vitalik Buterin and Gavin Wood.

Ethereum VM
Ethereum VM
Ethereum Virtual Machine (EVM)
EVM is the runtime environment used for smart contracts.
Quasi-Turing complete machine.
Since every Ethereum node runs the EVM, applications built on it are decentralized
without having to build their blockchain.
Solidity is the programming language, for Ethereum's Smart Contracts.
When you use Solidity to build a smart contract or any other application, the EVM
compiler takes that code, resolves it into lower level machine instructions for the
EVM to understand, process and execute.

Transactions
Transactions are signed data packages that store information to be sent between
different externally owned accounts. Transactions are executed to interact with
Ethereum network.

External accounts use contracts to perform transactions.


A transaction is composed of the following:
A message receipt containing the address of the Sender and receiver.
A nonce to keep track of the number transactions.
A signature to identify the Sender.
The number of Ether to be transferred from the Sender to the receiver.
The gas limit signifies the amount of gas to be spent for a transaction
The gas price signifies the fee Sender will pay for the transaction.

Ethereum Block Structure


The basic structure of block in a blockchain consists of four sections, the block
size, block header, transactions counter, and transactions.
The block header is the crucial part which is formed of several fields, namely, the
version, timestamp, previous block hash, Merkel root hash, difficulty target, and
nonce.
When the transactions are put in a Merkel tree, a Merkel root hash is created.
Nonce is a random number that is used in PoW.
The difficulty target is the measure of how hard it is to solve the PoW.
The main distinction between Bitcoin and Ethereum concerning the blockchain
architecture is that, unlike Bitcoin, Ethereum blocks include a copy of both the
most recent state and transaction list. Bitcoin only holds a copy of the
transaction list. Aside from that, two other values, the block number, and the
difficulty are also stored in the block.

The World Computer


Due to its ability to support Turing complete languages and run Decentralized
Applications using EVM, Ethereum is often termed as "the world computer".

Ethereum Network
The Ethereum network is a decentralized peer to peer (P2P) network of nodes that
interact with each other to build and maintain the Ethereum Blockchain and secure
it using different consensus mechanisms.

Websites like EthStats.net and ethstats.io are used to monitor the live statistics
of Ethereum blockchain.

ethernodes.org have the information about different nodes on the blockchain like
the node id and a client used.

Though Ethereum is inherently a public blockchain platform, it can also be used as


private and consortium blockchain.

Public blockchains: It is a blockchain that anyone can read and send transactions.
Consortium blockchain: It is a partly decentralized blockchain where a pre-selected
set of nodes controls the consensus process.
Private blockchains: It is a blockchain where write permissions are placed
centralized to one organization.

Ether
Ether
Ethereum, like Bitcoin Blockchain, has its cryptocurrency called Ether.
Ether is similar to Bitcoin and is used in transactions and also as an incentive
for mining the blocks.
Ether is also used to pay for another Ethereum token called Gas. Gas is an Ethereum
token used for computation of Smart Contracts.
Ether (ETH) will be issued at a constant annual linear rate via the block mining
process, at a rate of 5 ether per mined block.
The token release method of Ether (ETH) was done by Initial Coin Offering (ICO)
which is similar to Initial Public Offer (IPO).

Gas
Gas
Gas is a token that is used as a computational fee for the execution of Smart
contracts, every line of instruction in a smart contract requires a certain amount
of Gas for its execution.
A transaction requires a minimum of 21000 gas for its execution
GasPrice: the Gas price is the amount to be paid in Ether (ETH) to buy a Gas token.
The gas price is not constant and depends on the network traffic. The average Gas
price is 0.00000002 ETH(20 Gwei)
GasLimit: Gas Limit is the amount of gas paid by a sender for the transaction.
If some gas is left after the completion of a transaction it is returned in form
Ether
Similarly, if a transaction runs out of gas, it returns to its previous state
(i.e., no transaction is performed) and no gas is refunded. Therefore, it is very
important to know the Gas Limit.

ERC Tokens
The main difference between Ethereum and Ether tokens is that while the former is
an open source blockchain platform for building DAPPS and Smart contracts the later
is a smart contract developed on top of Ethereum to be used as a digital asset.
Tokens are issued to the public through a crowd sale called an initial coin
offering (ICO). The creators of the token will issue the token to others in
exchange for digital currencies like Ether and Bitcoin.

ERC-20 Tokens
ERC-20 is a standard in Ethereum that has certain rules that are to be followed by
a smart contract to be ERC-20-compliant. A token that implements all the
rules/functions of ERC-20 standard is called an ERC-20 token.
Most of the tokens in Ethereum are completely ERC-20 compliant.
If a Smart contract implements only some of the functions/rules of the ERC-20
token, it is partially ERC20 compliant.
ERC-20 standard defines a set of rules that are to be followed by the Ethereum
tokens in the Ethereum blockchain network. These set of rules implement actions
that govern the transfer of tokens, keep track of the number of tokens, and approve
transactions.

Mining
Mining is the process by which transactions are added to a blockchain.
Ethereum, like other public blockchains, follows an incentive-driven mechanism of
mining.
The people who do mining are called miners and are provided with incentives in the
form of Bitcoins and Ethers.
Since most blockchain networks are public and anyone can add transactions to the
blockchain, there's a need for a mechanism to verify and add valid transactions to
the blockchain to make it secure. This mechanism is called Consensus.

Mining
There are many methods used to reach a Consensus in blockchain, like the Byzantine
Fault Tolerant (BFT) algorithms, Proof of Work (PoW) algorithms, Proof of Stake
(PoS) algorithms and Delegated Proof of Stake (DPoS) algorithms.
The two most commonly used methods for reaching Consensus are PoW (Proof of Work)
and PoS (Proof of Stake).
What happens when there are more miners?
When the number of miners increases the difficulty of the Proof of Work problem
also increases, which in turn requires more computational resources to be solved.
The mining rewards decreases, and the value of Ether increases.

Proof of Work (PoW)


Proof of Work is the most common method used to reach consensus in the blockchain.
Proof of work requires the miner to perform a computationally intensive
mathematical calculation, to add transaction to the public blockchain.
This process adds a block to the public blockchain and also creates a new digital
currency. The miner who solves the mathematical puzzle (proof of Work problem)
first is rewarded with tokens (Bitcoin or Ether) as incentives.
Ethereum utilizes a Proof Of Work algorithm known as Ethash, which is a modified
version of the Dagger-Hashimoto algorithm.

Proof of Stake (PoS)


Proof of Stake (PoS) is an algorithm used for achieving consensus and adding a
transaction to the blockchain.
It was developed to overcome the drawback of the existing Proof of Work consensus
mechanism.
PoS algorithms achieve consensus by requiring miners to put a stake of their tokens
to have a chance of mining a block (adding a block to the blockchain). In PoS, the
miners are called as forgers.

Proof of Stake (PoS)


The higher the stakes, the more are the chances to add the block but the process is
not entirely dependent on the number of stakes. This would make it centralized to
the rich. Instead, most PoS algorithms use methods like Randomized block selection
and Coin Age Selection which make the consensus mechanism random.
In Proof of Stake, there is no mathematical problem to solve, and there are no
rewards for adding a block to the blockchain.
In PoS-based consensus mechanisms, the forgers are rewarded with the transaction
fee instead of tokens.
The Proof of Stake consensus mechanism is expected to be added to Ethereum with the
Serenity update.

What are Ethereum Clients?


Ethereum clients are nodes that can connect to the Ethereum blockchain network, and
perform all the blockchain operations such as creating and verifying transactions,
executing smart contracts and everything related to the blockchain. Ethereum
clients implement Ethereum's technical specifications using several programming
languages.

Ethereum clients provide Command Line tools that help to perform the following
tasks:
Join the Ethereum network.
Interact with the network.
Create transactions.
Create accounts.
Create and run smart contracts.
Mine new blocks.

Types of Ethereum Clients


There are various Ethereum Clients developed using different Programming Languages.

Eth

The C++ implementation of the client is called Eth.


If you require additional security by operating two different implementations
simultaneously or are curious about GPU mining, then you can use C++ “Eth” client.
Suitable for GPU mining, IoT and contract development
cpp-ethereum is exceptionally portable and is utilized on a wide range of
platforms.
Github Repo: https://github.com/ethereum/aleth.

Geth
Geth is a top-rated Go programming based Ethereum Client.
Geth offers a command line interface for running a full Ethereum node.
It is security audited Go client for use with Mist (a GUI to interact with Smart
Contracts), suitable for Dapp development.
Geth’s synchronization is --fast solution to the scalability problem.
Geth can connect to test networks like Ropsten and Rinkeby (Proof of Authority
based testnet).
By installing and running Geth, you can take part in the Ethereum frontier live
network. You can also do the following tasks:
Mine real Ether.
Transfer funds between addresses.
Create contracts and send transactions.
Explore block history.
GitHub Repo: https://github.com/ethereum/go-ethereum.

Parity
Parity

Parity along with Geth is one of the most popular Ethereum client.
It is light and fast Ethereum client.
It is written in the Rust language.
It does not support Rinkeby testnet but supports Kovan (similar to Rinkeby).
Improved reliability, performance, and code clarity.
Parity is being developed by Ethcore.
GitHub Repo: https://github.com/ethcore/parity.

Pyethapp
Pyethapp is a Python-based Ethereum Client.
Pytehapp was developed by Vitalik Buterin, the founder of Ethereum.
The Ethereum foundation is developing a new thoroughly documented EVM, the py-evm
which is implemented using python.
Pyethapp leverages two Ethereum core components to implement the client:
Pyethereum - the core library, featuring the blockchain, EVM, and Mining.
Pydevp2p - the p2p networking library, featuring node discovery for and transport
of multiple services over multiplexed and encrypted connections.
GitHub Repo: https://github.com/ethereum/pyethapp.

Connecting with Ethereum Clients


Ethereum clients expose several methods over JSON-RPC for interacting with them
from within an application.
Disadvantages of interacting directly over JSON-RPC:

JSON-RPC protocol implementation


Binary format encoding/decoding for creating and interacting with smart contracts.
256-bit numeric types.
Admin command support - e.g., create/manage addresses, sign transactions.
Many libraries are available that can rectify above problems, and can be connected
with the Client.

Library Language Project Page


web3.js JavaScript https://github.com/ethereum/web3.js
web3j Java https://github.com/web3/web3
Nethereum C# .NET https://github.com/Nethereum/Nethereum
ethereum-ruby Ruby https://github.com/DigixGlobal/ethereum-ruby

Web3.js
Web3.js
Web3.js is a JavaScript library (Ethereum Javascript API) that is used to interact
with the Ethereum blockchain using different communication protocols the HTTP, or
the IPC connection.

It interacts with the Ethereum network using the JSON-RPC (JSON remote procedure
call).

The Web3.js library has different modules for different functionalities.

web3-eth is for Ethereum blockchain and smart contracts.


web3-shh is for the whisper protocol to communicate p2p and broadcast.
The web3-bzz is for the swarm protocol, the decentralized file storage.
The web3-utils contains useful helper functions for DApp developers.
Adding web3.js library
To run the web3.js library, you need the NPM package manager of node.js.
Install Node.js to get the NPM package manager and install the web3 library.
$ npm install web3

Connecting to Network
You can connect to the Ethereum Blockchain by using Ethereum clients such as Geth,
Parity, and Eth.

Installing Geth Ethereum Client on Ubuntu


sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
To start the Geth ethereum client, type geth in the terminal, geth automatically
downloads the ethereum blockchain data.
The --fast flag is used for fast synchronization with the blockchain but does not
have the past transaction data.
Geth connects you to the other nodes in the Ethereum blockchain until it has peers.
Geth finds peers through a discovery protocol.
In the discovery protocol, nodes are continuously communicating with each other to
discover other nodes on the network.
To start a node without discovery protocol, you can use the --nodiscover flag.

Checking Network Connectivity


Checking connectivity and Ethereum Node IDs
To check how many peers, the Geth client is connected to you have to open the Geth
console (an interactive Javascript environment).
You can open it typing geth console, and check the connectivity by typing the
following commands in the geth console:
> net.listening
true
> net.peerCount
4
To get more information about the connected peers, such as IP address and port
number, supported protocols, use the peers() function of the admin object.
admin.peers() returns the list of currently connected peers.

Test Networks
Testnets are used by developers to build and test DApps and smart contracts. They
have similar functionalities as the main Ethereum network.
The main difference between main networks and test networks is that the ethers in
test networks are worthless because they are used for testing purpose.
There are three main test networks currently in use, and each behaves similarly to
the production blockchain (where your real Ether and tokens reside).
Ropsten: A proof-of-work implemented blockchain network where you can mine false
ether. It is supported by geth.
Kovan: A proof-of-authority blockchain, started by the Parity team. Ether can’t be
mined; it has to be requested.
Rinkeby: A proof-of-authority blockchain, started by the Geth team. Ether can’t be
mined; it has to be requested.
You can access the testnets from Etherum wallets, browsers plugins like metamask
and directly through Ethereum clients.

Setting Up a Private Test Network


You can set up your private blockchain network in Ethereum using Geth Ethereum
client.

Step1: Create a genesis block, which is the first block of the blockchain.
Step 2: Create a folder of the same name as your blockchain network.
Step 3: Create a .json configuration file for the genesis block.
Example: myGenesis.json
{
"nonce": "0x0000000000000042",
"mixhash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x20000",
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x0",
"parentHash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0xffffffff",
"config": {
"chainId": 3889,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
}
}

Setting Up the Private Network


Step 4: Execute the geth command with the following flags
geth --identity "MyTestnet" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir
"myPrivateNetwork2" --port "30312" --rpcapi
"db,eth,net,web3,admin,debug,miner,personal,web3" --networkid 1900 --nat "any" init
myGenesis.json console
--identity: The name of the testnet
--rpcport: The port from where the testnet receives json roc calls.
--datadir: Path of the directory that stores the private chain data.
--nodiscover: This makes the testnet private and not discoverable by other peers.
Step 5: Open a new terminal and use the geth attach command this attaches the
terminal to the first geth instance. e.g.,
geth attach http://127.0.0.1:8080

What are Ethereum Accounts?


An Ethereum account is a 20-byte address that can store the “state” of ownership of
ether tokens. Each transaction is a transition of ownership between Ethereum
accounts. An account has four fields to process the transition:

A counter that is utilized to ensure each transaction is processed only once is


known as a nonce.
The account owners ether balance
The account’s smart contract code
The account’s storage

Types of Ethereum Accounts


There are two types of Ethereum Accounts:

Externally owned Accounts (EOAs): External accounts are the accounts that have a
private key associated with it.
Contract Accounts: Contract Accounts have a code associated with them.

Keyfiles
Every account is defined by a pair of keys, a private key, and public key.
Accounts are indexed by their address which is derived from the public key by
taking the last 20 bytes.
Every private key/address pair is encoded in a keyfile.
JSON text files
Keyfiles are found in the keystore subdirectory of Ethereum node’s data directory.

Creating Account Using geth


Using geth account new
$geth account new
Your new account is locked with a password. Please give a password. Do not forget
this password.
Passphrase:
Repeat Passphrase:
Address: {168bc315a2ee09042d83d7c5811b533620531f67}
$ geth --password /path/to/password account new

For non-interactive use, you provide a plaintext password file as argument to the
--password flag. The data in the file includes the raw bytes of the password
optionally followed by a single newline.

Using the --password flag is meant to be used only for testing or automation in
trusted environments.

It is a wrong idea to save your password to file or disclose it in any other way.

If you do use the --password flag with a password file, ensure the file is not
listable or even readable for anyone but you.

To list all the accounts $ geth account list


account #0: {a94f5374fce5edbc8e2a8697c15331677e6ebf0b}
account #1: {c385233b188811c9f355d4caec14df86d6248235}
account #2: {7f444580bfef4b9bc7e14eb7fb2a029336b07c9d}

Transaction Costs
The total ether cost of a transaction is based on two factors:
gasUsed is the total gas that is used by the transaction
gasPrice price (in ether) of one unit of gas mentioned in the transaction
Total cost = gasUsed * gasPrice
gasUsed is the sum of all the gas for all the operations executed. For estimating
gas used, there is an estimateGas API that can be used.
gasPrice - A user constructs and signs a transaction, and each user may specify
whatever gasPrice they desire, which can be zero.
However, the Ethereum clients started at Frontier had a default gasPrice of 0.05e12
wei. As miners optimize for their revenue, if most transactions are being submitted
with a gasPrice of 0.05e12 wei, it would be difficult to convince a miner to accept
a transaction that specified a lower, or zero, and gasPrice.

Ethereum Wallet
Ethereum Wallet
Ethereum Wallet is a place from where you can transact using ether. You can buy and
sell ether. It is different from traditional online wallets in the sense that it
does not store ether anywhere. It just keeps the balance of the ethers based on the
transactions.

Most Initial Coin Offerings (ICO) tokens are issued on Ethereum blockchain.
Not all digital wallets support Ethereum powered ICO tokens.
Wallets can be of many types like desktop, mobile, physical, and paper.
Some of the wallets that are verified to support Ethereum tokens are the official
Ethereum Wallet, Mist, MetaMask (a browser extension), Cold storage, Parity, and
imToken (for mobile devices).

Wallets: Classification
Wallets can be classified into many types based on the mode of access, how data is
stored, and they are used.

Hot Wallets and Cold Wallets: Hot Wallets store keys online, cold Wallets store
keys offline, and are therefore more secure.
Full node wallets and Lightweight wallets: Full node wallets download the entire
blockchain, and Lightweight wallets connect to other nodes to get blockchain data.
Virtual and Physical wallets: Virtual Wallets are wallets used on desktops, mobile
devices, and Browsers. Physical Wallets are Paper Wallets and Hardware Wallets.

Using Ethereum Wallets


Getting and Sending Ether using Ethereum Wallets
Getting ether To obtain Ether: - Become an Ethereum miner (see Mining), or - Trade
other currencies for ether using centralized or trustless services, or - Use the
user-friendly Ethereum Wallets, which can purchase ether. Sending ether

Ethereum Wallets supports sending ether via user friendly graphical interface.
Ether can also be transferred using the geth console.
> var sender = eth.accounts[0];
> var receiver = eth.accounts[1];
> var amount = web3.toWei(0.01, "ether")
> eth.sendTransaction({from:sender, to:receiver, value: amount})

Metamask
Metamask
Metamask is a web-based cryptocurrency wallet that comes as an extension for
browsers like Chrome, FireFox, and Brave.
It is a hot wallet that acts as a bridge and allows to run Smart Contracts and
Dapps on Ethereum Blockchain without downloading the entire blockchain.
To use Metamask wallet, you should have a web browser installed on your system.
It can be used to connect to the main Ethereum blockchain, test networks like
Ropsten, Rinkeby, and Kovan.
It can also be used to connect to your private blockchain.

Mist
Mist is a Browser interface and Etherum Wallet that is used to browse DApps, create
accounts and perform transactions
Mist is a very popular web-based tool to connect to the ethereum main network and
also connect to the geth ethereum client.
The main difference between Mist and Ethereum Wallet is that Mist has both Browser
and wallet functionalities built in it.

You might also like