Ethereum - Blockchain 2.0
Ethereum - Blockchain 2.0
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.
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.
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.
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.
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.
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.
Eth
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.
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).
Connecting to Network
You can connect to the Ethereum Blockchain by using Ethereum clients such as Geth,
Parity, and Eth.
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.
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
}
}
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.
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.
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.
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.