CCBT_Unit-IV
CCBT_Unit-IV
UNIT IV
HYPERLEDGER FABRIC & ETHEREUM
Components:
Hyperledger fabric is an enterprise-level permission blockchain network. It is
made up of various unique organizations or members that interact with each
other to serve a specific purpose. For example, these organizations can be a bank,
financial institution, or a supply chain network. Each organization is identified
and they have a fabric certificate authority. These organizations are called
members.
Each member of the fabric can set up one or more authorized peers to participate
in the network using the fabric certificate authority. All of these peers must be
authorized properly.
There is a client-side application connected to the network written with the
software development kit (SDK) of any particular programming language.
Workflow:
For each and every transaction in the fabric, the following steps are followed-
1
APEC
UNIT 4 CCBT
2
APEC
UNIT 4 CCBT
1. Supply Chain: Supply chains are global or regional webs of suppliers, manufacturers,
and retailers of a particular product. Hyperledger Fabric networks can improve the
transaction processes of the supply chain by increasing the clarity and traceability of
transactions within the fabric. On a Fabric network, enterprises having authentication to
access the ledger can view the data of the previous transactions. This fact increases
accountability and reduces the risk of counterfeiting of the transactions. Real-
time production and shipping updates can be updated to the ledger. Which can help us to
track the product condition in a much faster, simpler, and efficient way.
2. Trading and Asset Transfer: Trading and asset transfer requires many organizations or
members like importers, exporters, banks, brokers. They work with one another. And even
in the era of digitalization a lot of paperwork is going on in this sector. But using
Hyperledger they can transact and interact with each other in a paperless way. The
Hyperledger fabric can add the same layer of trust as the document signed by a trusted
authority. This also increases the performance of the system.
Another benefit of Hyperledger fabric is that assets can be dematerialized on the blockchain
network with the help of Hyperledger fabric. Due to this traders or stakeholders will be able
to have direct access to their financial securities and they can trade it anytime.
3. Insurance: The insurance industry spends billions to avoid insurance frauds or falsified
claims. With the help of Hyperledger fabric, the Insurance company can refer to the
transaction data that is stored inside the ledger. Hyperledger Fabric can also make the
processing of claims faster using the chain code and automate the payment. This process
will be also helpful for multi-party subrogation claims processing. Where it can automate
repayment from the fault party back to the insurance company. Verification of identity or
KYC process will be easy using this private blockchain.
3
APEC
UNIT 4 CCBT
authenticated members. This benefit is the most useful in industry-level cases, like banking,
insurance, etc where customer data should be kept private.
3. Access Control: In the Hyperledger fabric, there is a virtual blockchain network on top
of the physical blockchain network. It has its own access rules. It employs its own
mechanism for transaction ordering and provides an additional layer of access control. It is
especially useful when members want to limit the exposure of data and make it private.
Such that it can be viewed by the related parties only. As an example when two competitors
are on the same network. The fabric also offers private data collection and accessibility,
where one competitor can control the access to its own data such that the data do not get
exposed to the other competitor.
4. Chaincode Functionality: It includes a container technology to host smart contracts
called chain code that defines the business rules of the system. And it’s designed to support
various pluggable components and to accommodate the complexity that exists across the
entire economy. This is useful for some of the specific types of transactions like asset
ownership change.
5. Performance: As the Hyperledger fabric is a private blockchain network, There is no
need to validate the transactions on this network so the transaction speed is faster, resulting
in a better performance.
Hyperledger Fabric is a robust and flexible platform for developing blockchain applications,
but like any technology, it has certain limitations:
1. Scalability: Hyperledger Fabric is designed for permissioned networks, where
the participants are known and trusted, which can limit its scalability for large-
scale public networks.
2. Performance: The performance of Hyperledger Fabric can be impacted by
factors such as network size, network configuration, and the complexity of
chaincode, which can limit its ability to handle high volumes of transactions.
3. Complexity: Setting up and configuring a Hyperledger Fabric network can be
complex, requiring a deep understanding of the technology and its components.
4. Compatibility: Hyperledger Fabric is designed to be used with specific
programming languages, such as Go and JavaScript, which can limit its
compatibility with other technologies and programming languages.
5. Cost: Running a Hyperledger Fabric network requires infrastructure and
resources, which can add costs to the deployment and operation of blockchain
applications.
6. Interoperability: Hyperledger Fabric is designed to be used within a single
network, and its interoperability with other blockchain platforms is limited.
CHAIN CODE
Blockchain is the technology that has been making a lot of news lately. It’s a hot topic
because it’s believed to be revolutionary by many. Hyperledger Fabric is one of the leading
blockchain frameworks out there, and this article will explain what chain code is within
Hyperledger Fabric. The following topics will be discussed here:
1. What is chain code In Hyperledger Fabric?
2. Types of chain code In Hyperledger Fabric?
3. System Chain codes
4
APEC
UNIT 4 CCBT
5
APEC
UNIT 4 CCBT
6
APEC
UNIT 4 CCBT
business logic while taking into account all contributions from other
participants in the network, known as actors.
This includes both transactions between actors, such as customers or suppliers,
but also interactions with fabric-specific functions like transaction ordering or
reconciliation.
Within the context of blockchain development, smart contracts also refer to
contract code that is enforced by the distributed blockchain ledger and
executed automatically when a condition specified in the contract code is
triggered.
In this context, smart contracts are executable programmable logic (programs)
that are stored on the blockchain, which can only be run by authorized parties.
For operators, they can be used as a means of upgrading their distributed
ledger systems to provide new functionalities, such as allowing users to issue
assets and make transactions with them.
Chain code provides an interface for smart contracts to be programmed via
Chain code. Coda’s Chain code performs the following functions:
Chain code is launched in one of two ways in Coda: Either by invoking it via the
CLI or programmatically via SDK calls. In order for the node operator to launch
chain code, one must first authorize launch permissions by providing a list of
node IDs for which the chain code is authorized to run.
Chain codes should primarily be written using Go, but other languages such as
Python and NodeJS can also be used.
KEY TAKEAWAYS
7
APEC
UNIT 4 CCBT
The founders of Ethereum were among the first to consider the full potential of blockchain
technology beyond just enabling a secure virtual payment method.
Since the launch of Ethereum, ether as a cryptocurrency has risen to become the second-
largest cryptocurrency by market value. It is outranked only by Bitcoin.
A Historic Split
One notable event in Ethereum's history is the hard fork, or split, of Ethereum and Ethereum
Classic. In 2016, a group of network participants gained control of the smart contracts used
by a project called The DAO to steal more than $50 million worth of ether.
The raid's success was attributed to the involvement of a third-party developer for the new
project. Most of the Ethereum community opted to reverse the theft by invalidating the
existing Ethereum blockchain and approving a blockchain with a revised history.
However, a fraction of the community chose to maintain the original version of the
Ethereum blockchain. That unaltered version of Ethereum permanently split to
become Ethereum Classic (ETC).
The maximum number of bitcoins that can enter circulation is 21 million.The amount of
ETH that can be created is unlimited, although the time it takes to process a block of ETH
limits how much can be minted each year.The number of Ethereum coins in circulation as of
May 2024 is just over 120 million.
Another significant difference between Ethereum and Bitcoin is how the respective
networks treat transaction processing fees. These fees, known as gas on the Ethereum
network, are paid by the participants in Ethereum transactions and burned by the network.
The fees associated with Bitcoin transactions are paid to Bitcoin miners.
8
APEC
UNIT 4 CCBT
The upgrade added capacity to the Ethereum network to support its growth, which will
eventually help to address chronic network congestion problems that have driven up gas fees
EVM
Ethereum Virtual Machine (EVM) is designed as the runtime environment for smart
contracts in Ethereum. It is sandboxed and isolated from the other parts of the system. This
means that any operation on EVM should not affect your data or programs in any way, no
matter how many times you call a particular function on it.
An EVM is the runtime environment that executes Ethereum smart contracts.
Ethereum contains its own Turing-complete scripting language, called Solidity,
and with this comes a need to execute this code.
A program called the Ethereum Virtual Machine (EVM) can do this task.
It runs on top of the Ethereum network, meaning that all nodes reach a
consensus about what code should be executed at every given time.
Purpose of EVM
The Ethereum Virtual Machine (EVM) is a Turing complete programmable machine, which
can execute scripts to produce arbitrary outcomes. It has been built with the purpose of
being a “world computer” and has immense power.
It is the computer that stores data on blockchain, like bitcoin, but it also executes
code in smart contracts 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 blockchain. 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.
Ethereum Virtual Machine (EVM) is a program which executes scripts used to implement
certain operations usually in Ethereum blockchain.
The Ethereum Virtual Machine makes the process of creating new tokens on Ethereum
Blockchain easy. Here, script means a set of instructions or an algorithm which tells the
computer what it needs to do in order for something to work properly. The EVM requires
that one has access over any network node so as to be able to execute the desired
commands and create new tokens on the blockchain without any difficulties.
In Ethereum, there is something called a smart contract. These contracts have
some computer code which facilitates the exchange of money and information.
9
APEC
UNIT 4 CCBT
These contracts are predefined by the creator of the smart contract, in order to
ensure that a certain outcome will happen based on either what happens or
doesn’t happen.
Ethereum Virtual Machine provides Turing complete environment for execution
of scripts and smart contracts. This means that anything that can be implemented
with a computer can be run on EVM.
In the Ethereum ecosystem, EVM plays a vital role by providing a platform for
decentralized applications (DApps) to be built on top of it.
Ethereum Virtual Machine ensures that all transactions and smart contracts made on the
Ethereum blockchain are executed in correct and expected manner as desired by the smart
contract code. It serves as a platform for applications to be executed on.
In simple words, it can be said that Ethereum Virtual Machine facilitates DApp creation
and execution on the blockchain.
Ethereum Virtual Machine (EVM) has two parts:
EVM (the part that runs solidity source code): The EVM is written in C++
and uses LLVM as its compiler. It is a full-featured virtual machine with all the
features that you would want in a general purpose Smart Contract Virtual
Machine, such as support for multiple programming languages, security features,
runtime environments and more. It also allows you to write custom EVM
bytecode .
Uncles: These are small pieces of smart contracts or data stored on the
blockchain. This is a useful feature because it allows for you to store metadata
about your program. EVM Assembly: This is the bytecode of EVM, which you
can use as your programming language.
These are small pieces of smart contracts or data stored on the blockchain. This is a useful
feature because it allows one to store metadata about the program.
Actions: These are basic operations that one can perform on assets stored in
memory (and not on the blockchain), such as multiplication, addition, and so on.
Balance: This is the amount of Ether that one have at any time. So, if there is a
balance of 100 Ether and spend 10 Ether, the balance would be 90 Ether. Note
that this is not actually a variable, it’s just a part of memory where EVM stores
the data. This means that whenone tries to modify or read from it, it will return
execution with an error.
Block: This is an immutable storage for all actions and transactions related to
Ethereum in its lifetime up until this block in particular. These blocks can be
only 65,000 so this is not going to change.
Blockhash: This is a hash of the block in question. So, if you are looking at
stored on the blockchain under another name, this would be a hash of the data
stored there.
Block Number: This is a number indicating which block this particular
blockhash belongs to. It always starts from zero and increases every time there’s
a new block added to the chain. Note that blocks have timestamps associated
with them so you can tell how much time passed between two blocks.
Code: This is code executed in EVM that determines what action is going to be
taken when an input happens (such as transferring money).
10
APEC
UNIT 4 CCBT
Benefits of EVM
Execute untrusted code without risking data: One can execute untrusted code
without putting the data at risk. EVM guarantees that its computations will not
interfere with anything else happening in the system or with the personal files.
Can run complex smart contracts: One can run complex smart contracts in
EVM without worrying about how they interact with each other. One can write
them once and then run them on multiple platforms, which allows for the
creation of a single contract that runs on multiple computing environments.
Deterministic processing: Smart contracts written on EVM have access to all
of Ethereum’s states at any given time, allowing for processing to happen in a
deterministic way and giving more guarantees about their correctness. For
example, one cannot make an infinite loop in EVM by calling the same function
twice. It would stop executing and return a finite value.
Distributed consensus: One of the potential applications of Ethereum is to
allow for distributed consensus where everyone is running the same program but
from their own computers.
Robust against failure: This is a complex process because the network needs to
be able to come to a consensus at any given time. This way, the system becomes
more robust against failures of individual nodes and you can update several
nodes simultaneously without worrying that they might end up disagreeing with
each other because of how code was written.
Easy to write stateful contracts: From a developer perspective, EVM is
designed for writing smart contracts as well as for creating DApps
(decentralized applications), which are programs running on distributed
networks in a way that ensures all of them are seeing the same version. It also
makes it incredibly easy to write stateful contracts, which need access to some
kind of persistent storage.
TRANSACTION FEE
11
APEC
UNIT 4 CCBT
Transaction fees serve two essential purposes when it comes to blockchain networks. They
reward miners or validators who help confirm transactions and help protect the network from
spam attacks.
Transaction fees can be both small or large, depending on the network activity. Market forces
can also influence the fees you pay. While high fees can hinder wider blockchain adoption,
very low fees could potentially bring security concerns.
Transaction fees are and have been an essential part of most blockchain systems since their
inception. You are most likely to have come across them when sending, depositing, or
withdrawing crypto.
The majority of cryptocurrencies use transaction fees for two important reasons. First of all,
fees reduce the amount of spam on the network. It also makes large-scale spam attacks costly
and expensive to implement. Secondly, transaction fees act as an incentive for users that help
verify and validate transactions. Think of it as a reward for helping the network.
For most blockchains, transaction fees are reasonably cheap, but they can get quite expensive
depending on network traffic. As a user, the amount you choose to pay in fees determines
your transaction's priority in being added to the next block. The higher the fee paid, the
quicker the confirmation process.
As the world's first blockchain network, Bitcoin set the standard for transaction fees used by
many cryptocurrencies today. Satoshi Nakamoto realized that transaction fees could protect
the network from large-scale spam attacks and incentivize good behavior.
Bitcoin miners receive transaction fees as part of the process of confirming transactions to a
new block. The pool of unconfirmed transactions is called the memory pool (or mempool).
Naturally, miners will prioritize transactions with higher fees, which users agreed to pay
when sending their BTC to another bitcoin wallet.
Malicious actors who wish to slow down the network must therefore pay a fee associated
with each transaction. If they set the fee too low, miners will likely ignore their transactions.
If they put them at a suitable level, they incur a high economic cost. So, transaction fees also
act as a simple but effective spam filter.
On the Bitcoin network, certain crypto wallets allow users to set their transaction fees
manually. It's also possible to send BTC with zero fees, but miners will most likely ignore
such transactions, meaning they won't be validated.
12
APEC
UNIT 4 CCBT
Unlike some tend to believe, Bitcoin fees are not dependent on the amount sent but on the
transaction size (in bytes). For example, imagine your transaction size is 400 bytes, and the
average transaction fee is now at 80 satoshis per byte. In that case, you would have to pay
around 32,000 satoshis (or 0.00032 BTC) for a good chance of having your transaction added
to the next block.
When network traffic is high, and there is a great demand for sending BTC, the transaction
fee needed for speedy confirmation rises as other bitcoin users try to do the same. This may
occur during periods of intense market volatility.
As such, the high fees can make it challenging to use BTC in day-to-day situations. Buying a
$3 cup of coffee might not be practical if the fees are much higher than that.
Only a certain number of transactions can be included within a block, which has a limit of
1MB (i.e., block size). Miners add these blocks to the blockchain as quickly as possible, but
there is still a limit to how fast they can go.
The scalability of cryptocurrency networks is a crucial issue here in deciding network fees.
Blockchain developers are making continuous efforts to address the problem. Previous
network updates have helped improve scalability, such as the implementation of SegWit and
the Lightning Network.
Ethereum transaction fees work differently in comparison to Bitcoin's. The fee takes into
account the amount of computing power needed to process a transaction, known as gas. Gas
also has a variable price measured in ether (ETH), the network's native token.
While the gas needed for a specific transaction can stay the same, gas prices can rise or fall.
This gas price is directly related to network traffic. If you pay a higher gas price, miners will
likely prioritize your transaction.
The total gas fee is simply a price that covers the cost, plus an incentive to process your
transaction. However, you should also consider the gas limit, which defines what's the
maximum price paid for that transaction or task.
In other words, the gas cost is the amount of work required, and the gas price is the price paid
for “each hour” of work. The relation between these two and the gas limit defines the total fee
for an Ethereum transaction or smart contract operation.
13
APEC
UNIT 4 CCBT
Let's pick a random transaction on Etherscan.io as an example. The transaction cost 21,000
gas, and the gas price was 71 Gwei. So, the total transaction fee was 1,491,000 Gwei or
0.001491 ETH.
MIST BROWSER
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 popular 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.
Mist Browser?
The Mist browser was an attempt to develop a graphical user interface for the Ethereum
blockchain and virtual machine. It was sunsetted in 2019
ETHER
Ethereum is a decentralized blockchain platform that enables the development and
execution of smart contracts and decentralized applications (DApps). It provides a
14
APEC
UNIT 4 CCBT
foundation for building various blockchain-based solutions and allows for the creation of
programmable digital assets.
What is Ether?
Ether (ETH) is the native cryptocurrency of the Ethereum network. It serves as the fuel that
powers the execution of smart contracts, enables transactions, and facilitates interactions
within the Ethereum ecosystem.
Is Ether the same as Ethereum?
No, Ether and Ethereum are not the same. Ethereum is the blockchain platform, whereas
Ether is the cryptocurrency native to that platform. Ethereum provides the infrastructure
and capabilities for decentralized applications, while Ether is the digital asset used within
that ecosystem.
Ether Uses
Transaction Fees and Gas: Ether is used to pay transaction fees on the
Ethereum network. Users must include a fee, known as “gas,” to incentivize
miners or validators to process and validate transactions.
Smart Contract Execution: Ether is required to execute smart contracts on the
Ethereum network. It serves as the currency for deploying and interacting with
these self-executing agreements.
Decentralized Finance (DeFi): Ether plays a significant role in DeFi
applications. It can be used as collateral for loans, liquidity provision, yield
farming, and governance within DeFi protocols.
Token Creation and ICOs: Ether has been instrumental in the creation of
tokens on the Ethereum platform. Many projects conduct Initial Coin Offerings
(ICOs), raising funds by selling their tokens in exchange for Ether.
Interoperability and Integration: Ether can be tokenized as Wrapped Ether
(WETH) and used on other blockchain platforms, enabling interoperability and
seamless integration between Ethereum and other ecosystems.
How to Buy Ether?
To buy Ether, you can follow these steps:
1. Set up a cryptocurrency wallet that supports Ether.
2. Choose a cryptocurrency exchange that allows you to buy Ether.
3. Create an account on the exchange and complete the necessary verification
process.
4. Deposit funds into your account using fiat currency or other cryptocurrencies.
5. Place a buy order for Ether on the exchange, specifying the desired amount and
price.
6. Once the order is filled, the purchased Ether will be credited to your wallet.
How is Ether used to power DApps?
Ether plays a crucial role in powering DApps on the Ethereum network. It is used for:
Accessing DApp features: Ether can be required to access specific
functionalities, premium features, or services within a DApp.
In-App Purchases: DApps may allow users to make purchases using Ether.
This can include buying digital goods, virtual assets, or in-game items.
Decentralized Governance: Ether can be staked or used for voting within
decentralized autonomous organizations (DAOs) to participate in decision-
making processes and shape the direction of the organization or network.
Ether vs Bitcoin
Below is the difference between Ethereum and Bitcoin:
15
APEC
UNIT 4 CCBT
16
APEC
UNIT 4 CCBT
failure, and unauthorized alterations, providing users with increased trust and
confidence.
Potential for Growth and Adoption: Ether’s early adoption and continued
development make it well-positioned for potential future growth. As more
industries embrace blockchain technology and decentralized applications,
Ether’s value may increase as it becomes an integral part of innovative solutions
across various sectors.
GAS
Ethereum Gas is a section that calculates the quantity of calculation action that it
takes to perform specific functions. Every function that carries position in Ethereum like
transactions and smart contracts etc. performance needs some part of gas. It is essential to
the blockchain P2P network because it is the power that authorizes it to accomplish exactly
what an automobile needs fuel to drive. Gas refers to the cost required to complete a deal
on the Ethereum network.
Gas prices are delivered in the form of Ethereum’s born money, the currency
of Ethereum is ETH.
Gas costs are indicated in “gwei” which is a movement of Ethereum, every
single “gwei” is equivalent to 0.000000001 ETH.
For sample, rather than stating that the gas costs 0.000000001 ether, say, the gas
costs 1 “gwei”.
The term “gwei” means “Giga-wei”, which is equivalent to 1,000,000,000
“wei”.
“Wei” is called after “Wei Dai” that is the creator of b-money (least unit of
ETH).
Gas Fees
The gas fees include Base, Priority, Max, and calculating fees. Let’s discuss these terms in
detail.
1. Base fees:
Each alliance has a ground fee which serves as a fund price.
The ground fee is figured alone of the existing alliance and is rather specified by
the alliances before it pushes trade prices better for users.
When the block is excavated the base fee is “burned”, dragging it from
regulation.
The ground fee is evaluated by instructions that compare the length of the earlier
block with the marked size.
The base fee intention rise by a max of 12.5% per block if the marked block size
is surpassed.
2. Priority fee:
Apart from the base fee obtained, the advancement presented a priority fee i.e.
tip to miners to contain a trade in the alliance.
17
APEC
UNIT 4 CCBT
Without tips, miners can see it financially possible to drill cleared blocks
because they can obtain the exact alliance prize.
Under normal circumstances, a little tip provides miners with the slightest
encouragement to maintain a transaction.
For dealings that require getting preferentially conducted ahead of different
trades in the same block, a more elevated tip will be essential to endeavor to
outbid contending trades.
3. Max fee:
To conduct trade on the P2P network, users can select the greatest limit they are
inclined to spend for their dealing to be completed.
This additional circumference is called the max fee/Gas.
For a trade to be completed, the max fee must surpass the aggregate of the base
and priority fees.
The trade sender is repaid the contrast between the max fee and the total of the
ground(base) fee and tip.
4. Calculating fees:
The main benefit of the upgrade is enhancing the user’s knowledge when
charging trade fees.
In the wallets that sustain the upgrade rather than explicitly commenting to pay
the transaction from a wallet, providers will automatically set a suggested
transaction fee (base fee + suggested priority fee) to decrease the quantity of
complexness loaded on their users.
18
APEC
UNIT 4 CCBT
A more increased tip can construct it additional possible that your trade will
convey into the subsequent block.
The ETH efficiency advancements should eventually manage some of the gas
cost points, allowing the medium to process thousands of trades globally per
moment.
Second layer scaling is a direct ambition to significantly enhance gas prices, user
knowledge, and scalability.
The recent proof-of-stake(POS) sample based on the Beacon Chain, should
decrease heightened control consumption and dependence on technological
hardware.
This chain resolve permits decentralized ETH P2P networks to compromise and
support network security while restricting gas consumption by rather demanding
an economic responsibility.
Strategies to decrease gas costs for ETH, Users can select a direction to display
the important status of the user’s transaction.
Miners intention perform trades that suggest a more increased tip per gas, as
they hold the tips that users spend and resolve be slightly tilted to conduct
transactions with more down tips specified.
If users like to observe gas costs, then they can send ETH for smaller, user can
utilize multiple other tools given below:
” Etherscan Transaction gas price estimator “, and ” Blocknative ETH Gas
Estimator Gas ” for evaluating Chrome attachment backing both Class 0
inheritance trades and Class 2 EIP-1559 trades, and” ETH Gas Station ” which is
client instructed metrics for the Ethereum gas demand, ” Cryptoneur Gas Fees
Calculator ” is used for calculating gas prices in the local currency for various
trade.
Gas prices assist maintain the Ethereum grid safe. By demanding a price for
every analysis performed on the grid, it controls harmful attackers from
spamming the grid.
To bypass unexpected code, every trade needs to set a limitation to the multiple
computational efforts of regulation performance.
The absolute unit of analysis is “gas”.
Moreover, a trade contains a limitation, any gas not operated in a transaction is
produced to the user (i.e. max fee – (base fee + tip) is produced).
19
APEC
UNIT 4 CCBT
The base fee is computed by a procedure that resembles the dimensions of the last block
(the part of gas utilized for all the trades) with the target size. The base fee will rise by a
most of 12.5% per alliance if the target block size is overextended.
SOLIDITY
Solidity is a brand-new programming language created by Ethereum which is the second-
largest market of cryptocurrency by capitalization, released in the year 2015 and led by
Christian Reitwiessner. Some key features of solidity are listed below:
Solidity is a high-level programming language designed for implementing smart
contracts.
It is a statically typed object-oriented(contract-oriented) language.
Solidity is highly influenced by Python, c++, and JavaScript which run on the
Ethereum Virtual Machine(EVM).
Solidity supports complex user-defined programming, libraries, and inheritance.
Solidity is the primary language for blockchains running platforms.
Solidity can be used to create contracts like voting, blind auctions, crowdfunding,
multi-signature wallets, etc.
Ethereum
20
APEC
UNIT 4 CCBT
Smart Contract
Smart contracts are high-level program codes that are compiled to EVM byte code and
deployed to the ethereum blockchain for further execution. It allows us to perform credible
transactions without any interference of the third party, these transactions are trackable and
irreversible. Languages used to write smart contracts are Solidity (a language library with
similarities to C and JavaScript), Serpent (similar to Python, but deprecated), LLL (a low-
level Lisp-like language), and Mutan (Go-based, but deprecated).
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.4.16 < 0.9.0;
/// @title A contract for demonstrate how to write a smart contract
/// @author Jitendra Kumar
/// @notice For now,this contract just show to set the value of state variable,calculate the
sum and get this sum value from the smart contract
contract Test
{
// Defining function to
// print the sum of
// state variables
function get(
) public view returns (uint) {
return sum;
}
21
APEC
UNIT 4 CCBT
Explanation:
1. Version Pragma:
pragma solidity >=0.4.16 <0.9.0;
Pragmas are instructions to the compiler on how to treat the code. All solidity source code
should start with a “version pragma” which is a declaration of the version of the solidity
compiler this code should use. This helps the code from being incompatible with the future
versions of the compiler which may bring changes. The above-mentioned code states that it
is compatible with compilers of version greater than and equal to 0.4.16 but less than
version 0.9.0
2. The contract keyword:
contract Test
{
//Functions and Data
}
The contract keyword declares a contract under which is the code encapsulated.
3. State variables:
uint public var1;
uint public var2;
uint public sum;
State variables are permanently stored in contract storage that they are written in Ethereum
Blockchain. The line uint public var1 declares a state variable called var1 of type uint
(unsigned integer of 256 bits). Think of it as adding a slot in a database. Similarly, goes
with the declaration uint public var2 and uint public sum.
4. A function declaration:
function set(uint x, uint y) public
function get() public view returns (uint)
22
APEC
UNIT 4 CCBT
This is a function named set of access modifier type public which takes a
variable x and variable y of datatype uint as a parameter.
This was an example of a simple smart contract that updates the value of var1
and var2. Anyone can call the function set and overwrite the value of var1 and
var2 which is stored in the Ethereum blockchain. This is an example of a
decentralized application that is censorship-proof and unaffected to the
shutdown of any centralized server. As long as someone is running a single node
of the Ethereum blockchain, this smart contract will be accessible.
The variable sum is calculated by adding the values of the variables var1 and
var2.
Function get will retrieve and print the value of the state variable sum.
How to Execute The Code:
There are practically two ways to execute a solidity smart contract:
1. Offline Mode: Running a solidity smart contract in Offline mode requires three
prerequisites and 4 major steps to be followed to get the smart contract running:
Prerequisites:
Download and install node.js.
Install Truffle globally.
Install ganache-cli.
Objectives:
Create a truffle project and configure a development network
Create and deploy smart contracts
Interact with the smart contract from Truffle console
Write tests for testing the main features offered by Solidity.
2. Online Mode: Remix IDE is generally used to compile and run Solidity smart contracts
in the Online Mode
23
APEC