0% found this document useful (0 votes)
20 views

Final Unit 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Final Unit 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

UNIT IV

Hyperledger Fabric & Ethereum


Architecture of Hyperledger fabric v1.1- chain code- Ethereum: Ethereum network, EVM, Transaction fee,
Mist Browser, Ether, Gas, Solidity.

1. Concept of Ledger
•Ledger is constructed by the ordering service as a totally ordered hashchain of blocks of (valid or invalid)
transactions. The hash chain imposes the total order of blocks in a ledger and each block contains an array of
totally ordered transactions. This imposes total order across all transactions. •Ledger is kept at all peers and
optionally, at a subset of orders.
•A permissioned ledger is a ledger where actors must have permission to access the ledger. •Permissioned ledgers
map to closed trust-some or trust-all ledgers. Permission is granted in two different ways. The first is via a white
list, a list of actors allowed to join the ledger's community. The second is via a black list, a list of actors who are
banned from the ledger's community: a permissioned ledger using a black list would be a closed, trust-some ledger,
a permissioned ledger using a white list could be either an open or closed, trust-some ledger.
•A permissioned ledger introduces some form of access control in the way transactions are accessed and managed.
• A token ledger is a ledger requiring a currency to function, typically to pay the miners or to make denial of
service attacks economically challenging. Tokenless ledgers don't require a currency to operate.

Distributed ledger
•Distributed ledger is the core persistent layer in the blockchain architecture. It provides a decentralized and
distributed database containing the transaction entries. These entries are recorded in the order of its occurrence
and composed into hashed blocks.
•The database or the ledger, therefore, represents a chain of hashed blocks of transactions with each block referring
to the previous block in the chain. The ledger is shared across the blockchain network, which means every node
has a copy of the ledger, and each node verifies the transactions independently.
•When every node agrees and confirms the authenticity of the transaction, the ledger is said to be in consensus.
The blockchain network uses different consensus algorithms to arrive at the consensus.
•The consensus algorithm is a set of rules and conditions that governs the transaction. The blockchain network
implemented for the public has a permissionless ledger, while in a private network or a consortium, a ledger can
be made permissioned.
•The distributed ledger protocol of the fabric is run by peers. The fabric distinguishes between two kinds of peers:
1. A validating peer is a node on the network responsible for running consensus validating transactions and
maintaining the ledger.
2. Non-validating peer is a node that functions as a proxy to connect clients (issuing transactions) to validating
peers. A non-validating peer does not execute transactions but it may verify them.

2. Introduction of Hyperledger

•Hyperledger is an open source project created to support the development of blockchain- based distributed
ledgers. Hyperledger consists of a collaborative effort to create the needed frameworks, standards, tools and
libraries to build blockchains and related applications.
• Hyperledger Fabric is a consortium blockchain. Obtaining identity authentication and organizational permission
is a prerequisite for accessing the Fabric network. After joining the network, members jointly maintain a
distributed ledger. All data operations are public, and will be permanently recorded and cannot be tampered with.
• In Hyperledger Fabric, the communication security of each network node is guaranteed by the Public Key
Infrastructure (PKI), which signs and authenticates user identities and communication messages.
Hyperledger Fabric is a blockchain that achieves data privacy via "channels", which enable private
communications between two or more network members.
• It allows flexible network permission setup, as well as helps you to create private systems with inaccessible
blocks, meaning third parties can't extract any data from them.
•Transactions can be made confidential, only accessible to users with the necessary decryption keys.
•It can be utilized using various programming languages, such as C++, JavaScript, Python, Golang and Java.
•Hyperledger Fabric is a block chain framework. It works together with other Hyperledger projects such as Burrow
and Sawtooth to provide a scalable data platform. Hyperledger Fabric is a platform on which applications may be
developed.
•Hyperledger fabric is built upon a few central components:
a) Distributed ledger for all data recorded about the transactions
b) Multiple peers (or nodes)
c) Smart contracts that maintain transaction logic

Hyperledger Fabric Working


• A Hyperledger Fabric network is comprised of unique organizations or members that interact with each other
on the network. For example, an organization could be a bank in a network comprised of financial institutions or
a shipping partner in a supply chain network. From a Fabric component perspective, each organization has a
Fabric certificate authority and one or more peer nodes. A Fabric network also has an ordering service shared by
all organizations in the network, and this component helps process transactions for the network.
• An organization in a network is defined by a root certificate specific to that organization. Users and other
components in that organization are also identified by certificates and these certificates are derived from this root
certificate, ensuring other organizations in the network can relate a user to their organization. These certificates
also specify the permissions for each entity on the network, like read-only versus full access on a channel.
•A root certificate for an organization is stored in the Fabric Certificate Authority (CA). The Fabric CA also issues
certificates for users in an organization and handles other related operations. An enterprise-grade Fabric CA
utilizes a variety of components and can be deployed in a variety of ways using a Hardware Security Module
(HSM) for root certificate protection.
•An organization also creates one or more peer nodes as components to carry out operations on behalf of that
organization. Specifically, a peer node endorses transactions proposed on the network, stores and executes smart
contract code and stores a local copy of the ledger for access.
• Fabric clients typically interact with peer nodes to read the ledger, add new chain code to the network, or propose
a new transaction. A peer node typically runs on its own computer, like an Amazon EC2 instance.
• Finally, a Fabric network also includes an ordering service shared by all members of the network. The ordering
service makes sure new transactions on the network are properly ordered in new blocks and have the proper
endorsements.
• The ordering service then broadcasts a new block of transactions to peer nodes in each organization. Peer nodes
update their local copy of the ledger with this new block.

Properties of HyperLedger Fabric


• The properties of HyperLedger Fabric are as follows:
1. Identity management: A certificate authority is used to provide access to the permissioned blockchain. Each
organization has a root certificate with all the access.
2. Processing power: Hyperledger Fabric does not need a computationally intensive consensus algorithm because
it's a private blockchain. The consensus algorithms these blockchains use need less processing power.
3. Privacy: All the network nodes are verified before being added to the network.
4. Chaincode functionality: It allows companies to implement their business logic to perform transactions.
5. Modular design: This property allows organizations to personalize the blockchain network. It allows them to
choose the components and their settings, ranging from choosing the consensus algorithm to giving access to
different levels of access to nodes using the certificate authority.

Architecture of Hyperledger Fabric v1.1


• The reference architecture consists of various components that form a business blockchain. The Hyperledger
architecture working group has distinguished the following business blockchain components:
• Consensus layer: Responsible for generating an agreement on the order and confirming the correctness of the
set of transactions that constitute a block.
• Smart contract layer: Responsible for processing transaction requests and determining if transactions are valid
by executing business logic.
•Communication layer: Responsible for peer-to-peer message transport between the nodes that participate in a
shared ledger instance.
• Data store abstraction: Allows different data-stores to be used by other modules.
•Crypto abstraction: Allows different crypto algorithms or modules to be swapped out without affecting other
modules.
• Identity services: Enables the establishment of a root of trust during setup of a blockchain instance, the
enrollment and registration of identities or system entities during network operation and the management of
changes like drops, adds and revocations. Also, provides authentication and authorization.
• Policy services: Responsible for policy management of various policies specified in the system, such as the
endorsement policy, consensus policy, or group management policy. It interfaces and depends on other modules
to enforce the various policies.
• APIs: Enables clients and applications to interface to blockchains.
•Interoperation: Supports the interoperation between different blockchain instances.
• Identity: It provides authorization, identification, and authentication services under membership services.
• Policy: Policy component provides policy services.
• Ledger and transactions consists of the distributed ledger, ordering service, network protocols and endorsement
and validation services. This ledger is updateable only via consensus among the participants of the blockchain
network.
•Smart contracts layer, which provides chaincode services in Hyperledger and makes use of secure container
technology to host smart contracts.

Reference architecture of Hyperledger fabric

• From a components point of view Hyperledger contains various elements:


a) Consensus layer: These services are responsible for facilitating the agreement process between the participants
on the blockchain network. The consensus is required to make sure that the order and state of transactions is
validated and agreed upon in the blockchain network.
b) Smart contract layer : These services are responsible for implementing business logic as per the requirements
of the users. Transactions are processed based on the logic defined in the smart contracts that reside on the
blockchain.
c) Communication layer: This layer is responsible for message transmission and exchange between the nodes on
the blockchain network.
d) Security and crypto layer: These services are responsible for providing a capability to allow various
cryptographic algorithms or modules to provide privacy, confidentiality and non-repudiations services.
e) Data stores: This layer provides an ability to use different data stores for storing state of the ledger. This means
that data stores are also pluggable and allows usage of any database backend.
f) Policy services: This set of services provide the ability to manage different policies required for the blockchain
network. This includes endorsement policy and consensus policy.
g) APIs and SDKs: This layer allows clients and applications to interact with the blockchain. An SDK is used to
provide mechanisms to deploy and execute chaincode, query blocks and monitor events on the blockchain.

Architecture of a Hyperledger Fabric network.


• The transaction flow begins when a client application sends a transaction proposal to peers
in each organization for endorsement.
• The peers verify the submitting client's identity and authority to submit the transaction. Next, they simulate the
outcome of the proposed transaction and if it matches what was expected, it sends an endorsement signature back
to the client.
• The client collects endorsements from peers and once it receives the proper number of endorsements defined in
the endorsement policy, it sends the transaction to the ordering service.
• Lastly, the ordering service checks to see if the transaction has the proper number of endorsements to satisfy
the endorsement policy.
• It then chronologically orders and packages the approved transactions into blocks, and sends these blocks to peer
nodes in each organization. Peer nodes receive new blocks of transactions from the ordering service and then do
a final validation for transactions in that block. Once this is complete, the new block is added to the ledger and
the state of the ledger is updated. The new transactions are now committed.

Transactions in Hyperledger Fabric


• Transaction is an important element in Hyperledger Fabric. Transaction reflects the business activity upon the
fabric network. To achieve data immutability transactions are kept inside blocks and protected through a chained
structure.
• Client sends out a transaction proposal to the specified endorsing peer nodes (i.e. endorsers). Endorsers,
confirming the client is valid to send transaction proposal, execute the chaincode according to information
specified in the proposal and in world state.
• After execution they return the proposal response to the client. Inside the response is the simulation results done
by that endorser, in terms of a Read Write Set (RWSet), which shows what is read from the world state and what
is written back after the chaincode invoke. As an endorsement, endorsers sign the response.
• The client, after obtaining the responses, validates them to make sure things work fine. If collected responses
reach the required endorsing policy, the client constructs a transaction and send to orderer. The transaction
includes the transaction proposal, proposal response and endorsements.
• The orderer receives transaction(s) from the client(s) and validates them. Then orderer creates a block holding
the validated transactions, and broadcasts this newly created block to all the peer nodes. Upon receiving this block,
the peer node validates the block and executes the transaction inside the block, which will update the world state
according to the content in Read Write Set (RWSet). This block is now committed in each peer node as a valid
block.
Advantages and Disadvantages of Hyperledger Fabric

1. Advantages:

• Hyperledger Fabric is the basis for decentralized networks, where all participants have identifiers.
• Hyperledger Fabric is built on a modular architecture.
• Fabric decentralized book and smart contract platform allow private channels to be used.
• Fabric features a 'Hardware Security Model (HSM) that helps in safeguarding and managing digital keys used
for authentication.

2. Disadvantages:
• There is network fault tolerance.
• Inadequately skilled programmers.
• Lock of proven use cases.

3. Chaincode

• The chaincode is a program that handles business logic agreed to by members of the network, so it may be
considered as a 'smart contract'. Chaincode runs in a secured Docker container isolated from the endorsing peer
process. Chaincode initializes and manages ledger state through transactions submitted by applications.
• Chaincodes define the data schema in the ledger, initialize it, perform updates when triggered by applications,
and respond to queries. Chaincodes can also post events that allow applications to be notified and perform
downstream operations. For example, after purchase orders, invoices and delivery records have been matched by
a chaincode, it can post an event so that a subscribing application can process related payments and update an
internal ERP system.
• Chaincode is sandboxed in a secure container, which includes a secure operating system, chaincode language,
runtime environment, and SDKs for Go, Java and Node.js.
• The Fabric chaincode lifecycle is a process that allows multiple organizations to agree on how a chaincode will
be operated before it can be used on a channel. A network operator would use the Fabric lifecycle to perform the
following tasks:
1. Install and define a chaincode
2. Upgrade a chaincode
3. Deployment scenarios
4. Migrate to the new fabric lifecycle

Install and define a chaincode


• Fabric chaincode lifecycle requires that organizations agree to the parameters that define a chaincode, such as
name, version and the chaincode endorsement policy. Channel members come to agreement using the following
four steps. Not every organization on a channel needs to complete each step.

1. Package the chaincode: This step can be completed by one organization or by each organization.
2. Install the chaincode on peers: Every organization that will use the chaincode to endorse a transaction or query
the ledger needs to complete this step.
3. Approve a chaincode definition for organization: Every organization that will use the chaincode needs to
complete this step. The chaincode definition needs to be approved by a sufficient number of organizations to
satisfy the channel's Lifecycle Endorsment policy before the chaincode can be started on the channel.
4. Commit the chaincode definition to the channel: The commit transaction needs to be submitted by one
organization once the required number of organizations on the channel have approved. The submitter first collects
endorsements from enough peers of the organizations that have approved and then submits the transaction to
commit the chaincode definition.

4. Ethereum
Introduction of Ethereum
• Ethereum is a decentralized blockchain platform that establishes a peer-to-peer network that securely executes
and verifies application code, called smart contracts.
• Ethereum is a decentralized, open source and distributed computing platform that enables the creation of smart
contracts and decentralized applications, also known as dapps
• Ethereum is an open-source operating system that deals with smart contract functionality.

• Ethereum is open source and used primarily to support the second-largest cryptocurrency in the world known as
Ether.
• Ethereum is also a programming language that helps developers to create distributed applications. Ethereum
split into two different blockchains in 2016 namely Ethereum and Ethereum Classic.
• Ethereum aims to provide a system that gives users more control over their data and it also allows for applications
to be built and run on the blockchain. To run these applications and have this level of control on the Ethereum
platform, it requires Ether.
• Ethereum smart contract: A smart contract is application code that resides at a specific address on the blockchain
known as a contract address. Applications can call the smart contract functions, change their state and initiate
transactions. Smart contracts are written in programming languages such as Solidity and Vyper and are compiled
by the Ethereum Virtual Machine into bytecode and executed on the blockchain.
• Ethereum is the major distributed software application. It supports to build smart contracts and distributed
applications without downtime or third-party interference. Ethereum permits the developer to create and broadcast
next-generation distributed applications.
• The Ethereum platform permits developers to form powerful decentralized applications with in-built economic
functions. Though providing high accessibility, auditability, transparency and neutrality, it also reduces or
eliminates censorship and decreases assured counterparty risks.
• These centralized systems are good extensive models for software applications. This system directly controls
the operation of the individual units and the flow of information from a single center. In this kind of system,
individuals are dependent on the central power to send and receive information.
• The Ethereum blockchain has a native coin that is known as Ether (ETH), which is used to pay for activity on
the Ethereum blockchain. The coin also trades on crypto exchanges and fluctuates in value.

Features of Ethereum

Ethereum features are as follows:


1. Ether: This is the digital token of the Ethereum blockchain.
2. Smart contracts: Ethereum allows the development and deployment of smart contracts,
3. Ethereum virtual machine: Ethereum provides the underlying technology, the architecture, and the software
that understands smart contracts and enables people to interact with it.
4. Decentralized applications (Dapps): Ethereum allows people to create consolidated applications, called
decentralized applications. A decentralized application is called a Dapp.
5. Decentralized Autonomous Organizations (DAOs): Ethereum enables users to create these for democratic
decision-making. DAOs operate entirely transparently and independently of any intervention, with no single
leader.

Types of Ethereum Accounts

• An account is the minimum storage requirement, just like an address in the Bitcoin protocol. Accounts are one
of the main building blocks of the Ethereum blockchain.
• The state transition is achieved using what's called the Ethereum state transition function, which works as
follows:
1. Confirm the transaction validity by checking the syntax, signature validity, and nonce.
2. The transaction fee is calculated and the sending address is resolved using the signature.
3. Provide enough Ether (gas price) to cover the cost of the transaction.
4. In cases of transaction failure due to insufficient account balance or gas, all state changes are rolled back except
for fee payment, which is paid to the miners.
5. Finally, the remainder (if any) of the fee is sent back to the sender as change and fees are paid to the miners
accordingly. At this point, the function returns the resulting state which is also stored on the blockchain.
• There are two types of accounts on Ethereum: externally owned accounts and contract accounts.
• An Externally Owned Account (EOA) is controlled by a private key. A Contract Account (CA) is controlled by
a piece of code in place of the private.key.
• Each account, regardless of its type consists of the following four elements:
1. Nonce: A number corresponding to the amount of (a) transactions sent from or (b) Contracts created by an
account.
2. Balance: amount owned by an account.
3. storage Root: A hash of the root node of a hash tree that encodes the storage contents of the account.
4. codeHash: A hash of the account's EVM code.

• EOAs are like to accounts that are controlled by a private key in bitcoin. Contract accounts are having private
key along with the accounts that have code associated with them.
• An EOA has ether balance, is capable to send transactions and has no related code, whereas a Contract Account
(CA) has ether balance, associated code and the ability to get caused and accomplish code in response to a
transaction or a message that due to the Turing extensiveness property of the Ethereum blockchain network, the
code within contract accounts can be of one of the level of complexity.

Externally owned account


• The basic function of an externally owned account is that it can hold an ether balance. Externally owned accounts
are further capable of sending and receiving transactions.
• The concept of externally owned accounts is quite similar to the concept of addresses in the Bitcoin protocol.
That being said, an Ethereum account is controlled by a private key that corresponds to its public key.
• The latter is hashed to determine the account address, while the former is used to generate signatures and
authorize outbound transactions.
• But because the Ethereum blockchain has an extended functionality that goes beyond that of the Bitcoin protocol
sending a transaction from an externally owned account is not limited to cryptocurrency transfers alone.
• Instead, an account is also capable of triggering contract code, meaning that it can be used to deploy smart
contracts or trigger smart contract functionality.

Transactions and Messages


• A transaction in Ethereum is a digitally signed data packet using a private key that contains the instructions that,
when completed, either result in a message call or contract creation.
• Transactions can be divided into two types based on the output they produce:
1. Message call transactions: This transaction simply produces a message call that is used to pass messages from
one contract account to another.
2. Contract creation transactions: As the name suggests, these transactions result in the creation of a new contract
account. This means that when this transaction is executed successfully, it creates an account with the associated
code.
• There are a few essential parameters that are required when creating an account. These parameters are as follows:
1. Sender
2. Original transactor (transaction originator)
3. Available gas
4. Gas price
5. Endowment, which is the amount of ether allocated
6. A byte array of an arbitrary length
7. Initialization EVM code
8. Current depth of the message call/contract-creation stack
Full nodes and light-weight nodes
1. Full nodes: Full nodes contain the entire history of transactions since the genesis block. They are a full-fledged
proof of the integrity of the blockchain network. Full nodes have to contain each and every transaction that has
been verified according to the rules set up by Ethereum's specifications.
2. Light-weight nodes: Light-weight nodes on the other hand only contain a subset of the entire blockchain. These
types of nodes are mostly used in e-wallets which have to be light-weight in nature and hence the entire blockchain
cannot be stored on them.
• These nodes do not verify every block or transaction and may not have a copy of the current blockchain state.
They rely on full nodes to provide them with missing details.
• The advantage of light nodes is that they can get up and running much more quickly, can run on more
computationally memory constrained devices and don't eat up nearly as much storage.

Ethereum Block
Ethereum blocks consist of following components:
1. The block header
2. The transactions list
3. The list of headers of ommers or uncles
• The transaction list is just a list of all transactions involved in the block. In adding, the list of headers of Uncles
is also incorporated in the block. The utmost significant and difficult part is the block header. Block header: The
block headers are the most serious and comprehensive components of an
Ethereum block. The header contains valued information, which is described in detail here.
1. Parent hash: This is the Keccak 256-bit hash of the parent (earlier)block's header.
2. Ommers hash: This is the Keccak 256-bit hash of the list of Ommers (Uncles) blocks included in the block.
3. Beneficiary: This field contains the 160-bit address of the receiver that will accept the mining payment once
the block is fruitfully mined.
4. State root: This field contains the Keccak 256-bit hash of the root node of the state tries.
5. Transactions root: This root is the Keccak 256-bit hash of the root node of the transaction tries. Transaction
tries denotes the list of transactions involved in the block
6. Receipts root: The receipts root is the Keccak 256 bit hash of the root node of the transaction receipt tries. This
tries is to collected of receipts of entirely transactions involved in the block.
7. Logs bloom: The logs bloom worked as a bloom filter that is collected of the logger address and log topics from
the log entry of each transaction receipt of the involved transaction list in the block.
8. Number: The count of total number of all earlier blocks; the origin block is block zero.
9. Gas limit: The field contains the value that represents the limit set on the gas intake per block.
10. Gas used: The field contains the total gas spent by the transactions included in the block.
11. Timestamp: Timestamp is the period Unix time of the time of block initialization.
12. Extra data: Extra data field can be used to supply arbitrary data related to the block.

Ethereum Stack Components


• Level 1 (Ethereum Virtual Machine): EVM is the runtime environment for smart contracts in Ethereum. All
smart contracts and state changes on the Ethereum blockchain are executed by transactions. The EVM handles all
of the transaction processing on the Ethereum network.
• Level 2 (Smart Contracts): Smart contracts are the executable programs that run on the Ethereum blockchain.
Smart contracts are written using specific programming languages that compile to EVM bytecode.
• Level 3 (Ethereum Nodes): In order for an application to interact with the Ethereum blockchain, it must connect
to an Ethereum node. Connecting to a node allows you to read blockchain data and/or send transactions to the
network. Ethereum nodes are computers running software an Ethereum client.
• Level 4 (Ethereum Client APIs): Many convenience libraries (built and maintained by Ethereum's open source
community) allow your applications to connect to and communicate with the Ethereum blockchain.
Level 5 (End-user Applications): At the top level of the stack are user-facing applications. These are the standard
applications user regularly use and build today: primarily web and mobile apps.

Types of Ethereum Network

• Two types of Ethereum network are Mainnet and Testnets.


1) Mainnet:
• Mainnet is the primary public Ethereum production blockchain, where actual-value transactions occur on the
distributed ledger
• A mainnet is a self-governing blockchain running its own network with its own technology and protocol. Mainnet
is a live blockchain anywhere its particular cryptocurrencies or tokens are in usage, as related to a testnet or
developments running on top of other popular networks such as Ethereum.
• Mainnet is the real blockchain network used for "actual" transactions with "monetary value", your wallet is set
to Mainnet by default.

2. Testnet:
• Testnet on the other hand is a testing network that runs the same protocol as Mainnet does and is used for testing
purposes. It allows you to experiment without having to use valuable coins on the main network (Mainnet).
• The programmers use testnet to troubleshoot and experiment any new features on a blockchain.
• The main dissimilarity between testnets and mainnets is that the previous is a blockchain project that is in
progress, while the latter encompasses a completely developed blockchain.
• A testnet is used by programmers and developers to test and troubleshoot all the aspects and features of a
blockchain network before they are sure the system is secure and ready for the mainnet launch.
• In other words, a testnet only exists as a working prototype for a blockchain project, while a mainnet is a
completely developed blockchain platform for users to send and receive cryptocurrency transactions.

Difference between Ethereum and Bitcoin

Basis Bitcoin Ethereum

Definition Ethereum is a decentralized global


Bitcoin (abbreviation: BTC; sign: ₿) is a
software platform powered by
decentralized digital currency that can be
blockchain technology. It is most
transferred on the peer-to-peer bitcoin
commonly known for its native
network.
cryptocurrency, ether (ETH).

History The word bitcoin was defined in a white Ethereum was conceived in 2013 by
paper published on 31 October 2008. The programmer Vitalik Buterin, and then
currency began use in 2009. went live on 30 July 2015.

Purpose The purpose of Ethereum was to


The purpose of bitcoin was to replace
utilize blockchain technology for
national currencies during the financial
maintaining a decentralized payment
crisis of 2008.
network and storing computer code.

Smart Contracts Although bitcoin do have smart contracts, Ethereum allows us to create smart
they are not as flexible or complete as contracts. Smart contracts are
Ethereum smart contracts. Smart contracts computer codes that is stored on a
Basis Bitcoin Ethereum

in Bitcoin does not have all the blockchain and executed when the
functionality that a programming language predetermined terms and conditions
would give them. are met.

Smart Contract Smart contracts on Bitcoin are written in Smart contracts on Ethereum are
Programming programming languages like Script, written in programming languages like
Language Clarity. Solidity, Vyper, etc.

Transactions Generally, bitcoin transactions are only for Ethereum transactions may contain
keeping notes. some executable code.

Hash Algorithm Bitcoin runs on the SHA-256 hash Ethereum runs on the Keccak-
algorithm. 256 hash algorithm.

Consensus The Proof-of-Work (PoW) is the


The Proof-of-Stake is the consensus
Mechanism consensus mechanism used by the Bitcoin
mechanism used by Ethereum.
network.

Block Time The block time of Ethereum is 14 to


The block time of bitcoin is 10 minutes.
15 seconds.

Block Limit The bitcoin blockchain has a block limit of The Ethereum blockchain does not
1 MB. have a block limit.

Popularity Ether, native currency of Ethereum is


Bitcoin is the most popular digital
the second-largest cryptocurrency after
currency in the market to date.
bitcoin to date.

Energy Energy consumption is very low as


Energy consumption is very high.
Consumption compared to bitcoin

Energy
Energy consumption rate of bitcoin Energy consumption rate of bitcoin
Consumption
mining system 3.2 Million household. mining system 1.2 Million household.
rate

Structure Structure of Ethereum is complex and


Structure of bitcoin is simple and robust.
feature rich

Rewards Miner got nearly 6.25 BTC on Miner got nearly 5 BTC along with
successfully adding new block in network. same additional rewards on
Basis Bitcoin Ethereum

successfully adding new block in


network.

Assets Assets of Bitcoin is BTC. Assets of Ethereum is Ether.

Difference between Ethereum and Hyperledger

Feature Ethereum Hyperledger

Confidentiality Public blockchain Private blockchain

Purpose Client-side B2C applications Enterprise-level B2B applications

Governance Ethereum Developers Linux Foundation

Participation Organizations having Certificate of


Anyone
Authorization

Programming
Solidity Golang, JavaScript, or Java
Language

Consensus Mechanism POW- Proof of Work


Pluggable consensus mechanism
Mechanism

Speed of Transactions Less More

Cryptocurrency Ether or Ethereum None

Real-World Applications of Ethereum

• Voting systems: Voting systems are implemented by using Ethereum. The outcomes of polls are widely
presented, confirming a transparent and fair self-governing procedure by removing passed by vote misuses.
• Banking systems: Ethereum is accomplishment approved extensively in banking application since with
Ethereum's decentralized system, provides strong security for data and unauthorized access to hacker is denied.
• Shipping: Deploying Ethereum in shipping benefits with the pursuing of cargo and prevents goods from being
misdirected or imitated. Ethereum makes available the derivation and tracking framework for any asset required
in a typical supply chain.
• Agreements: With Ethereum smart contracts, arrangements can be preserved and implemented without some
alteration. So in a business that has disjointed applicants, is subject to disagreements and needs digital contracts
to be contemporaneous, Ethereum is a technology for developed smart contracts and for digitally recording the
agreements and the transactions based on them.

5. Ethereum Virtual Machine


• The Ethereum Virtual Machine or EVM is a piece of software that executes smart contracts and computes the
state of the Ethereum network after each new block is added to the chain.
• The EVM sits on top of Ethereum's hardware and node network layer.
• The EVM is Etherum's native processing system that allows developers to create smart contracts and lets nodes
seamlessly interact with them. Ethereum developers write smart contracts with Solidity, a programming language
much like Javascript and C++.
• These smart contracts written in Solidity can be read by humans but not computers. It, therefore, has to be
converted into low-level machine instructions called opcodes, which the EVM can easily understand and execute.
• It's important to know every Ethereum node has its own EVM.
• When a person sends a transaction to a smart contract deployed on Ethereum, every node runs the smart contract
and the transaction through their own EVM.
• In this simulated environment, each node can see what the end result will be and whether the outcome produces
a valid transaction or not. If all nodes reach the same valid outcome, the changes are made and the updated
Ethereum state is recorded on the blockchain.
• EVM works with a word size of 256 bits and has several addressable data components:
1. An immutable program code ROM, loaded with the bytecode of the smart contract to be executed.
2. A volatile memory, with every location explicitly initialized to zero.
3. A permanent storage that is part of the Ethereum state, also zero-initialized.
Addressable data components of EVM are as follows:
• The Ethereum Virtual Machine has a stack-based architecture. It stores all in-memory values on a stack. It does
work with a word size of 256 bits. That is mainly to facilitate native hashing and elliptic curve operations.
• It has various addressable data components:
a) An immutable program code ROM: It is loaded with the bytecode of the smart contract to be performed.
b) A volatile memory: That is contained with every location, explicitly initialized to zero.
c) Permanent storage: It is a part of the Ethereum state. It is similarly zero-initialized
• There are three main types of storage available for contracts and the EVM:
1. Memory: The first type is called memory or volatile memory, which is a word-addressed byte array. When a
contract finishes its code execution, the memory is cleared. Write operations to the memory can be of 8 or 256
bits, whereas read operations are limited to 256-bit words. Memory is unlimited but constrained by gas fee
requirements.
2. Storage: The other type is called storage, which is a key-value store and is permanently persisted on the
blockchain. Keys and values are each 256 bits wide. It is allocated to all accounts on the blockchain. As a security
measure, storage is only accessible by its own respective CAs. It can be thought of as hard disk storage.
3. Stack: EVM is a stack-based machine, and thus performs all computations in a data area called the stack. All
in-memory values are also stored in the stack. It has a maximum depth of 1024 elements and supports the word
size of 256 bits.

Purpose of EVM
The Ethereum Virtual Machine (EVM) is a Turing complete programmable machine, which can execute sc
ripts to produce arbitrary outcomes. It has been built with the purpose of being a “world computer” and ha
s immense power.
 It is the computer that stores data on blockchain, like bitcoin, but it also executes code in smart contract
s on the Ethereum network.
 The machine is made to be able to run any kind of Crypto-contract that can be built on Ethereum’s bl
ockchain. It does this by using a programming language called Solidity, which is compiled into the EVM
for execution.
 The intention behind writing code on the Ethereum network is to create smart contracts and programs that
automatically execute things when certain conditions are met. If a terms or condition is not met, the
system can execute it in an “exit” function as well.
 For example, if an account has been hacked, the hacker cannot steal money from the system, because they
don’t have the budget or authority to do so.

Working of EVM
• The EVM uses a stack-based architecture and a word size of 256 bits. The 256-bit word size allows the EVM to
facilitate native hashing and elliptic curve operations that ensure funds can be spent only by their rightful owners.
• The storage associated with the EVM is a word-addressable word array that is non-volatile and is maintained as
part of the system state. Keys and values are 32 bytes in size and storage. The program code is stored in virtual
read-only memory (virtual ROM) that is accessible using the CODECOPY instruction. The CODECOPY
instruction copies the program code into the main memory. Initially, all storage and memory are set to zero in the
EVM.
•The design of the EVM where the virtual ROM stores the program code that is copied into the main memory
using the CODECOPY instruction. The main memory is then read by the EVM by referring to the program counter
and executes instructions step by step. The program counter and EVM stack are updated accordingly with each
instruction execution.
•EVM stack on the left side showing that elements are pushed and popped from the stack. It also shows that a
program counter is maintained and is incremented with instructions being read from the main memory. The main
memory gets the program code from the virtual ROM/storage via the CODECOPY instruction.

Design of EVM
• The EVM supports various programming languages such as Vyper and Solidity, with Solidity being the most
popular programming language for smart contract source code. These programming languages are used to write
smart contracts, which are converted into the bytecode needed to be utilized by the EVM.
• The bytecode stored on-chain, known as the runtime bytecode, is then converted into an opcode that the EVM
computation engine interprets to carry out those actions.
• When an Ethereum transaction executes a smart contract, an EVM is loaded with the information for the
transaction being processed. For example, one variable needed for a smart contract execution is the gas supply,
which is set to the amount of gas paid by the sender.
• The gas supply is reduced as the transaction progresses, and if, at any point, the gas supply reaches zero, the
transaction is abandoned. Although abandoned transactions don't result in changes to the Ethereum state and are
not considered valid transactions, the block's beneficiary is paid for providing resources up to the halting point.
• Smart contracts can initiate transactions and call other contracts on their own. In this case, each call results in
another EVM being loaded with specific information for the new transaction. This new information is initialized
from the EVM one level above.
• If there isn't enough gas to complete the execution, the state is discarded and the transaction execution is reset
to the EVM one level above.

Advantages of the EVM


• The EVM permits anyone to create their own DApp.
• There are infinite potential use cases for this type of software.
• Technology isn't prohibited to a particular group of people.
• There are several potential advantages of smart contracts.
• The latest example will be non-fungible tokens (NFTs).
• Everyone may create digital art and sell it on a decentralized marketplace by creating NFTs.
• This provides easy access to the art market in a virtual way that wasn't possible earlier.
6.Mist Browser

• The Mist browser was intended to be an integral part of the Ethereum network's dApps
(decentralized applications) ecosystem. It was the first graphical user interface that enabled
users to access the blockchain at a time when you could only access it via the command line.
• Mist browser is a user-friendly interface for end users with a feature-rich graphical user interface that is used to
browse Decentralized Applications (DApps) and for account management and contract management.
• Mist browser is not a wallet; in fact, it is a browser of DApps and provides a user-friendly user interface for the
creation and management of contracts, accounts, and browsing decentralized applications. Ethereum wallet is a
DApp that is released with Mist.
• Mist was the first browser that allowed users to browse dApps and it had an Ethereum wallet built in. It was also
the first desktop crypto wallet with a graphical user interface.
• The Mist Ethereum wallet itself would run on a user's computer, which meant it had to be downloaded, installed
and run locally.
• Mist browser was based on electron, an open-source project that aims to ease the creation of cross-platform
applications using JavaScrip.
• The Mist browser was a decentralized app on the Ethereum network from 2015 to 2019.
• Mist was the first browser that allowed users to browse dApps, and it had an Ethereum wallet built in. It was
also the first desktop crypto wallet with a graphical user interface (GUI).
• Mist was deprecated in March 2019 after developers decided other browser developers and wallet makers
were better able to create products for this quickly evolving space.

Understanding the Mist Browser


The Mist browser was an Ethereum interface intended to allow users to access the various dApps available on
the Ethereum network. It was also known as the Ethereum dApp Browser. Ethereum is a blockchain optimized
for smart contracts and other decentralized applications.As a dApp browser, Mist was a standalone application
with a graphical user interface (GUI) that allowed users to sync to the blockchain. It also provided an easy way
for users to create their own dApps and deploy tokens and other smart contracts in a non-technical way. The
Mist Ethereum wallet itself would run on a user’s computer, which meant it had to be downloaded, installed,
and run locally.The Mist browser was intended to allow users access to decentralized apps available on
the Ethereum network, similar to the way Chrome, Firefox, or Internet Explorer enables users to access
websites.

Reasons the Mist Browser Failed


Security
The Mist browser was based on Electron, an open-source project that aims to ease the creation of cross-
platform applications using JavaScript. Electron, in turn, is based on the Chromium open-source browser
developed by Google in 2008.Because Mist was effectively two layers away from updates pushed to
Chromium browsers, it was also farther away from fixes to Chromium vulnerabilities that needed crucial
security patches. The layer between Mist and Chromium (i.e., Electron) was not updated frequently enough to
keep up to date with Chromium, leading to an increased potential for attacks or data leakage over time.

7.Ether

• Ether is the name of the crypto-currency used to pay for transactions on the Ethereum network. Asides from
paying for general transactions and services, Ether is also used to buy gas, which in turn is used to pay for
computation within the EVM.
•Ether is the metric unit and has a lot of denominations which help accurately pay for transactions and gas. The
smallest denomination a.k.a base unit is called Wei.
•Ether (ETH) is the native cryptocurrency of Ethereum. The purpose of ETH is to allow for a market for
computation. Such a market provides an economic incentive for participants to verify and execute transaction
requests and provide computational resources to the network.
• Any participant who broadcasts a transaction request must also offer some amount of ETH to the network as a
bounty. The network will award this bounty to whoever eventually does the work of verifying the transaction,
executing it, committing it to the blockchain, and broadcasting it to the network.
•The amount of ETH paid corresponds to the resources required to do the computation. These bounties also
prevent malicious participants from intentionally clogging the network by requesting the execution of infinite
computation or other resource-intensive scripts, as these participants must pay for computation resources.

•ETH is also used to provide crypto-economic security to the network in three main ways:
1) It is used as a means to reward validators who propose blocks or call out dishonest behavior by other validators.
2) It is staked by validators, acting as collateral against dishonest behavior if validators attempt to misbehave their
ETH can be destroyed.
3) It is used to weigh 'votes' for newly proposed blocks, feeding into the fork-choice part of the consensus
mechanism.

There are multiple ways for an individual to obtain Ether.


1) It can be purchased on an exchange using a fiat currency under the symbol ETH.
2) It can be exchanged for Bitcoin on exchanges that offer a BTC-ETH pair.
3) It can be transferred to you from another person or entity.
4) It can be earned as a miner, through joining a mining pool or by purchasing a cloud mining contract.

8.Gas
•Gas keeps the Ethereum blockchain safe. It is what also allows (previously) miners (now) validators to profit and
provides incentive for doing the necessary work of proposing the next block of transactions for the blockchain.
So, what exactly is gas, and how does it work?
•Gas is a fee placed on top of any transaction on the Ethereum network, which is paid directly to the miner or
validators who is making the effort to validate and execute the bytecode of a transaction. Gas also keeps the
network safe through stopping an attacker from overloading the Ethereum network with transactions, Gas is the
resource that enables the execution of code in the EVM environment, measured in wei (a unit of ether). Just like
you need gas to power your car in real life, the EVM needs gas to execute operations.
•Gas is used as a metric for paying for computational resources on the network. Every contract on the network
has a set maximum amount of gas that it can use for its computations. This is known as the "Gas Limit".
• Gas price: This is the cost of gas in terms of tokens like Ether and its other denominations. To stabilize the value
of gas, the gas price is a floating value such that if the cost of tokens or currency fluctuates, the gas price changes
to keep the same real value.
Gas fee: This is effectively the amount of gas needed to be paid to run a particular transaction or program.
•While Ethereum and polygon use the term "gas fees," other blockchains such as Solana and Bitcoin use the term
"transaction fees." "Gas" comes from the fee's similarity to the fuel which keeps a vehicle running.
• Gas fees are also important in blockchain protocols using the proof-of-stake (PoS) consensus mechanism, such
as the next evolution of Ethereum, Ethereum 2.0. On these blockchains, gas fees reward validators who first
commit a certain amount of cryptocurrency to the network in order to be selected to verify new transactions.
• Two factors determine the amount of gas required by a transaction:
1. The complexity of the transaction.
2. The current load on the Ethereum network.
First factor: The normal way to update a blockchain is that a block filled with transactions is proposed and accepted
into the blockchain. For each of these transactions, a miner/validator must validate them and execute their
bytecode, which is composed of instructions.
• The base cost to have some transaction validated is 21000 gwei, where one gwei is one one- billionth, or
0.000000001 ETH. Then, an additional fee is placed on top of the base cost, determined by the amount of
instructions to be executed.
Each opcode has an associated gas cost, and when executed, consumes that amount of gas.
When we get to more complicated bytecode in smart contract transactions, the amount of instructions executed
drastically increases, which is why gas fees are higher for smart contracts than for static transactions. Second
factor: For determining the price of a transaction is the current load, or how heavily congested the Ethereum
network is.
• The formula for calculating gas is:
Gas price Gas units X (Base fee + Tip)
• The base fee's price is determined by Ethereum's network congestion. The tip is a priority fee and is set
automatically by most wallets to speed up our transaction's completion, so it's not very important when calculating
gas.
• The base fee for the current block is calculated based on previous blocks. When a new block is added onto the
blockchain, there is a set amount of gas, called included gas, that it can hold.
•In the block with the lowest base fee of 100 gwei, block number 1, included gas is 15M gwei. If the included gas
is completely filled, the base fee will increase by a maximum of 12.5% per block and the block number will
increase.

9. Solidity
•Solidity is the main programming language for writing smart contracts for the Ethereum blockchain. It is a
contract-oriented language, which means that smart contracts are responsible for storing all of the programming
logic that transacts with the blockchain.
•Solidity is an object-oriented programming language created specifically by the Ethereum network team for
constructing and designing smart contracts on blockchain platforms.
• It is a high-level programming language that looks a lot like JavaScript, Python, and C++. It's designed to run
on the Ethereum Virtual Machine, which is hosted on Ethereum nodes that are connected to the blockchain.
• It is statically typed and supports inheritance, libraries and more. In short, it has all the capability that we need
in order build industrial strength blockchain applications.

How to execute the code in Solidity program?


• Solidity program is executed in two ways: Offline mode and Online mode
1. Offline mode: To operate a Solidity smart contract in Offline mode, it must meet three conditions and follow
four essential actions:
a) Conditions
• Download and install node.js.
• Install Truffle globally.
• Install ganache-cli.

b) Actions
• Create a truffle project and set up a development network for it.
• Develop and deploy a smart contract for it.
• From the Truffle console, interact with the smart contract.
• Create tests to evaluate Solidity's primary features.

2. Online mode: In the Online mode, the Remix IDE is typically used to compile and run Solidity smart contracts.

Data Types Supported by Solidity Programming


• It supports all the common data types seen in other OOP languages, such as,
a) Boolean: The Boolean data type returns '1' when the condition is true and '' when it is false, depending on the
status of the condition.
b) Integer: You can sign or unsign integer values in Solidity. It also supports runtime exceptions and the 'uint8'
and 'uint256' keywords.
c) String: Single or double quotes can denote a string.
d) Modifier Before executing the code for a smart contract, a modifier often verifies that any condition is rational.
e) Array: The syntax of Solidity programming is like that of other OOP languages, and it supports both single and
multidimensional arrays.

Error Handling Mechanism in Solidity Programming


• Error handling mechanism in solidity programming is handled by the four functions:
1) assert() function: Assert is used when the outcome is predictable to be true, significance that we use assert to
test inner conditions.
2) require() function: Require is used when testing inputs, set our beliefs for those conditions. This function acts
as a gate condition, checking execution of the rest of the function and creating an error if it is not satisfied.
3) revert() function: Revert functions halt the execution of the contract and revert any state variations. The revert
function can also takings an error message as the one argument and it is recorded in the transaction log.
4) throw() function: The throw function is obsolete and will be removed in future versions of Solidity, you should
use revert instead.

Creation of a New Instance in Solidity


• The not dangerous technique to call an additional contract is if users build that additiona contract yourself. So
we can use certain of its interfaces and behavior. By using new keyword we can simply instantiate it.
• In Solidity programming the new keyword is used to create the contract on the blockchain and also return an
object that user can use to reference it.

• Let's say user need to make and call a Faucet contract from in an additional contract called Token:

contract Token is mortal


{
Faucet faucet;
constructor()
{
_faucet = new Faucet();
}
}
• This mechanism for contract building guarantees that you distinguish the particular kind of the contract and its
interface.

import "Faucet.sol";
contract Token is mortal
{

Faucet faucet;
constructor()
{
_faucet new Faucet();
}
}
contract Token is mortal
{
Faucet faucet;
constructor()
{
faucet new Faucet();
}
}
• This mechanism for contract building guarantees that you distinguish the particular kind of the contract and its
interface.

import "Faucet.sol";
contract Token is mortal
{
Faucet faucet;
constructor()
{
_faucet= new Faucet();
}
}

• You can similarly then call the Faucet functions. In this below example, we call the detroy function of Faucet
from in the destroy function of Token:
import "Faucet.sol";
contract Token is mortal
{
Faucet_faucet;
constructor()
{
_faucet = new Faucet();
}
function destroy() owner Only
{
_faucet.destroy();
}

You might also like