LABORATORY MANUAL
BLOCKCHAIN TECHNOLOGY LAB
B.TECH.
SEMISTER VII
DEPARTMENT OF COMUPER
ENGINEERING
Faculty Name: Dr. Moresh Mukhedkar
Department of Computer Engineering
INDEX
Sr. No. Name of Experiment Date
Group C: Blockchain Technology
1. Installation of Metamask and study spending Ether per transaction
2. Create your own wallet using Metamask for crypto transactions
Write smart contract on test network, for bank account of a customer
for following operations:
3. a)Deposit Money
b)Withdraw Money
c)Show Balance
4. Write a survey report on types of Blockchains and its real time use cases
Mini Project
5.
Create a dApp(de-centralized app)for e-voting system.
Assignment no. 1 and 2
Assignment 1: Installation of Metamask and study spending Ether per transaction
Assignment 2: Create your own wallet using Metamask for crypto transactions
1. MetaMask
1.1 Introduction
MetaMask is a plug-in Ethereum crypto wallet for Chrome onboard users. Available as a
browser extension and as a mobile app, MetaMask equips us with a key vault, secure login,
and token wallet—everything we need to manage our digital assets. MetaMask provides the
simplest yet most secure way to connect to blockchain-based applications. In this and following
labs, we will use MetaMask to store and send tokens not only between our accounts, but also
in smart contracts.
1.2 MetaMask Setup
Complete information and study guide about MetaMask can be found at its official website
metamask.io. We need to choose the right browser (Chrome is recommended) and follow its
installation instruction. When we are creating a new MetaMask account, here are some key
points we need to pay attention to. First of all, creating a new strong password is extremely
important because it encrypts private key.As we discussed in the lecture, private keys give
access to all of our Ether or other tokens. So, it is better to have a strong password here.Secret
Backup Phrase, which includes 12 mnemonic words, will pop out after setting up the password.
We need to write this phrase on a piece of paper or store it in a secure location because secret
backup phrase makes easier to back up and restore our account if we log out our account or
accidentally clear browser history. We are now able to use interact with MetaMask.
How to Install and Use Metamask on Google Chrome?
MetaMask is a type of Ethereum wallet that bridges the gap between the user interfaces for
Ethereum (For example, Mist browsers, DApps) and the regular web (For example, Google
Chrome, Mozilla Firefox, websites). Its function is to inject a JavaScript library called web3.js
into the namespace of each page your browser loads. Web3.js is written by the Ethereum core
team. MetaMask is mainly used as a plugin in the web browser. Let’s walk through the steps
to install it on Google Chrome.
Step 1: Go to Chrome Web Store Extensions Section.
Step 2: Search MetaMask.
Step 3: Check the number of downloads to make sure that the legitimate MetaMask is being
installed, as hackers might try to make clones of it.
Step 4: Click the Add to Chrome button.
Step 5: Once installation is complete this page will be displayed. Click on the Get
Started button.
Step 6: This is the first time creating a wallet, so click the Create a Wallet button. If there is
already a wallet then import the already created using the Import Wallet button.
Step 7: Click I Agree button to allow data to be collected to help improve MetaMask or else
click the No Thanks button. The wallet can still be created even if the user will click on the No
Thanks button.
Step 8: Create a password for your wallet. This password is to be entered every time the
browser is launched and wants to use MetaMask. A new password needs to be created if chrome
is uninstalled or if there is a switching of browsers. In that case, go through the Import
Wallet button. This is because MetaMask stores the keys in the browser. Agree to Terms of
Use.
Step 9: Click on the dark area which says Click here to reveal secret words to get your secret
phrase.
Step 10: This is the most important step. Back up your secret phrase properly. Do not store
your secret phrase on your computer. Please read everything on this screen until you understand
it completely before proceeding. The secret phrase is the only way to access your wallet if you
forget your password. Once done click the Next button.
Step 11: Click the buttons respective to the order of the words in your seed phrase. In other
words, type the seed phrase using the button on the screen. If done correctly the Confirm button
should turn blue.
Step 12: Click the Confirm button. Please follow the tips mentioned.
Step 13: One can see the balance and copy the address of the account by clicking on
the Account 1 area.
Step 14: One can access MetaMask in the browser by clicking the Foxface icon on the top
right. If the Foxface icon is not visible, then click on the puzzle piece icon right next to it.
1.2 Spending Ethereum per transaction
1.2.1 Deposit Ether
Following steps can be completed on either MetaMask website or its extension interface (we
can enter the interface from browser’s extension toolbar, which is on the top-left corner for
Chrome). First of all, we have to choose a right network to make our first transaction. There
are several options for the networks: main network, local host, custom RPC and test networks,
which include Ropsten, Kovan, Rinkeby and Goerli. The default network is Main Ethereum
Network where we can trade real Ether. In this and following labs, we are going to use Rinkeby
Test Network (you may also use other test networks) in which we can use free test Ether from
the third-party websites. Testing on Main Network may cost too much real Ether which is
unaffordable for developer like
us. By clicking ‘Main Ethereum Network’ in website or interface, it will give us several choices
and we are going to choose ‘Rinkeby Test Network’ for our developers’ environment.
Steps how to deposit Ether
Deposit some Ether in your MetaMask accounts.
By following the steps in faucet.rinkeby.io, anyone that has a Twitter or Facebook account may
request Rinkeby Ether within the permitted limits. If you want to use tokens in other
networks,you can search ‘free ether on (network’s name) test network’ or click ‘Deposit’ in
MetaMask interface.
1.2.2 Make A Transaction
In this section, we are going to make a transaction between our accounts. We only have one
default account right now, but we definitely need to create more accounts.
By clicking the top-right account picture in MetaMask interface, we can see ‘Create Account
button. By clicking that button and entering the account name, we will switch back to the
account where we deposited Ether, click ‘Send’, enter an amount of Ether, select an account
we want to transfer to and choose the speed to send Ether. Depending on the speed we choose,
the transaction usually takes about 15 - 30 seconds. While we are waiting for it to be completed,
we can find this transaction in ‘Queue’ (or in ‘History’ if the transaction is finished). By
clicking ‘View on Etherscan’, we will find transaction details including Transaction Hash,
Status, Block, Timestamp, From, To, Transaction Value and Transaction Fee. As we can see,
our transaction has been recorded in Rinkeby Network, and anybody in the Rinkeby can see
our blocks.
How to spending Ether
Create several accounts and make some transactions between these accounts.
There is a term called gas that we all pay when we want to make a transaction or execute a
contract on the Ethereum blockchain platform. So, typically gas is the internal pricing for
running a transaction or contract in the Ethereum network.
Every time a transaction(development purpose) is to be carried out or any contract deployed
on the local blockchain, MetaMask displays a prompt, detailing the requested transaction,
along with the Gas price(very low) as well as any other Ether amount that might have to be
sent and for that, test ethers will be used for payment. Below is an example of MetaMask
prompt message for paying gas.
Note: Test ethers are used only for development purposes in a way they are fake ethers.
Steps To Get Free Ethers
Step 1: Set up your MetaMask properly.
First, go to the Chrome web store and search for MetaMask. You can get MetaMask
extension from here.
Install the extension.
For using MetaMask you need to finish the signup/new-account procedure.
Step 2: Switch your network to the Rinkeby test network in MetaMask. You will see your
current balance for the Rinkeby test network.
Step 3: Copy your account address by just clicking on your account address.
Step 4: Go to the Rinkeby Faucet website using the below-given
URL- https://faucet.rinkeby.io/
Step 5: You will land on an interface like this:
Step 6: Now there are two ways to get ether either using Twitter post or Facebook post. You
can go with any of them though going with Twitter will be an easy choice.
Step 7: Tweet the account address that you have copied earlier. Below is an example of the
tweet.
Step 8: Copy your Tweet URL and paste it in the input box on the page of the Rinkeby Faucet
website.
Step 9: On the right side of the input box there is a “Give me Ether” dropdown containing
three options with ether amounts click on any clicked amount of test ether will be transferred
to your given account address in the tweet.
Step 10: The ether transfer process may take 2-15 minutes to be done. When test ethers
funded to your account you will see something like this.
After the process completed you will see something like this in your MetaMask.
Assignment no. 3
Title: Write smart contract on test network, for bank account of a customer for
following operations:
a)Deposit Money
b)Withdraw Money
c)Show Balance
1.4 Smart Contract
• A smart contract is a self-executing contract with the terms of
the agreement betweenbuyer and seller being directly written
into lines of code.
• The code and the agreements contained therein exist across a
distributed,decentralized blockchain network.
• The code controls the execution, and transactions are trackable and
irreversible.
Figure 3.1 illustration of Smart contract
Smart contracts work by following simple
“if/when…then…” statements that arewritten into code on
a blockchain.
A network of computers executes the actions when
predetermined conditions havebeen met and verified.
These actions could include releasing funds to the
appropriate parties, registering avehicle, sending
notifications, or issuing a ticket.
The blockchain is then updated when the transaction is completed.
That means the transaction cannot be changed, and only
parties who have beengranted permission can see the
results.
Within a smart contract, there can be as many stipulations
as needed to satisfy theparticipants that the task will be
completed satisfactorily.
Participants must determine how transactions and their data
are represented on theblockchain.
Participants agree on the “if/when...then…” rules that
govern those transactions,explore all possible exceptions,
and define a framework for resolving disputes.
The smart contract can be programmed by a developer.
organizations that use blockchain for business provide templates, web
interfaces, andother online tools to simplify structuring smart contracts.
Benefits of smart contracts
1) Speed efficiency and accuracy
Once a condition is met, the contract is executed immediately. Because smart
contracts aredigital and automated, there’s no paperwork to process. No time
spent reconciling errors that often result from manually filling in documents.
2) Trust and transparency
Because there’s no third party involved, and because encrypted records of
transactions areshared across participants, there’s no need to question whether
information has been altered for personal benefit.
3)Security
Blockchain transaction records are encrypted, which makes them very hard to hack.
Moreover, because each record is connected to the previous and
subsequent records on adistributed ledger, hackers would have to alter the
entire chain to change a single record.
4)Savings
Smart contracts remove the need for intermediaries to handle transactions and,
byextension, their associated time delays and fees.
Applications of smart contracts
Smart contracts can be used across industries to streamline and automate doing
businessaround the world.
1) Government - voting system
2) Management
Single ledger as a source of trust, accuracy, transparency, and automatesystem
3) Supply chain
Automates tasks and payment
4) Automobile
With the help of smart contract insurance company can be connected for claim
5) Real Estate
No need of Brokers, real estate agents
6) Healthcare
Assignment no. 4
Title: Write a survey report on types of Blockchains and its real time use cases
4.1 Types of Blockchain
1. Public Blockchains
2. Private Blockchains
3. Consortiums Blockchains
4. Hybrid Blockchains
Public Blockchains
• Public blockchains are open, decentralized networks of computers accessible to
anyone wanting to request or validate a transaction (check for accuracy).
• Those (miners) who validate transactions receive rewards.
• Public blockchains use proof-of-work or proof-of-stake consensus.
• permission-less distributed ledger system.
• Anyone who has access to the internet can sign in on a blockchain platform to
become an authorized node and be a part of the blockchain network.
• Example : Bitcoin and Ethereum (ETH) blockchains.
Figure 4.1 public blockchain
A public blockchain has some characteristic features:
• Write-only, immutable, transparent data storage.
• It brings trust among the whole community of users
• Decentralized, no need for intermediaries.
• Consistent state across all participants.
• Resistant against malicious participants.
• Anyone can join the public blockchain.
Disadvantages
• They suffer from a lack of transaction speed.
Private Blockchains
• A Private Blockchain is just like a relational database i.e. fully centralized and owned
by a single organization.
• Private blockchains are not open, they have access restrictions.
• People who want to join require permission from the system administrator.
• They are typically governed by one entity, meaning they’re centralized.
• For example, Hyperledger is a private, permissioned blockchain.
Figure 4.2 private blockchain
Consortiums blockchain
• Validation is conducted by known and identified members of the limited network of
nodes
• greater privacy since the information from verified blocks is not exposed to the
public.
• There are no transaction fees
• consensus is reached by a relatively small number of nodes in accordance to the
governance scheme.
Figure 4.3 Consortium blockchain
• Increased scalability - Bitcoin’s block transmits only up to 1 Mb* (from 1500 to 2700
transactions) per 10 minutes, when a consortium blockchain can optimize it to 1000
and more transactions per second.
• A consortium platform is more flexible.
• voting-based system, it ensures low latency and superb speed.
Hybrid Blockchain
• like a consortium blockchain, but it is not.
• Hybrid blockchain is best defined as a combination of a private and public
blockchain.
• It has use-cases in an organization that neither wants to deploy a private blockchain
nor public blockchain and simply wants to deploy both worlds’ best.
• Example of Hybrid Blockchain: Dragonchain, XinFin’s Hybrid blockchain
Advantages
• Works in a closed ecosystem without the need to make everything public.
• Rules can be changed according to the needs.
• Hybrid networks are also immune to 51% attacks.
• It offers privacy while still connected with a public network.
• It offers good scalability compared to the public network.
Disadvantages
• Not completely transparent.
• Upgrading to the hybrid blockchain can be a challenge.
• There is no incentive for participating and contributing to the network.
Table 1.2 Types of blockchain
Public Private Hybrid
The hybrid blockchain is
The public a combination of the
Private blockchain is
blockchain is open public and private
controlled by owners
Definition to everyone where blockchain. This means
and access is limited
anyone can that some process is kept
to certain users.
participate. private and others
public.
The public The private blockchain Hybrid blockchain
blockchain is is only transparent to transparency depends on
Transparency
completely the users who are how the owners set the
transparent. granted access. rules.
Public blockchain The private blockchain
incentivizes is limited and hence Hybrid blockchain can
Incentive participants for have no similar opt to incentivize users
growing the incentive as that of a if they want to.
network. public blockchain.
Can be used in Hybrid is best suited for
Private blockchain is
almost every projects that can neither
great for organization
industry. Good for go private or public
blockchain
public projects. It is and have a lack of trust.
Use-case implementation as
also good for The supply chain is a
they require complete
creating great example. It is also
control over their
cryptocurrency for effective in banking,
workflow.
commercial use. finance, IoT, and others.
Bitcoin, Litecoin,
Example Ripple, Corda Hyperledger
Ethereum
KYC needed No Yes Yes
Transactional
Costly Not so costly Not so costly
Cost
Carries basic
property of Yes Yes Yes
blockchain
Use cases
• Dubai has been able to integrate blockchain into eight industry sectors
• Real estate
• Tourism
• Security
• Transportation
• Finance
• Health
• Education.
• The end result is to become the world’s first blockchain city.
Assignment no. 5
Title: Create a dApp(de-centralized app)for e-voting system.
Decentralized Voting System using Blockchain
Blockchain is a technology that is rapidly gaining momentum in era of industry 4.0. With high
security and transparency provisions, it is being widely used in supply chain management systems,
healthcare, payments, business, IoT, voting systems, etc.
Why do we need it?
Current voting systems like ballot box voting or electronic voting suffer from various security
threats such as DDoS attacks, polling booth capturing, vote alteration and manipulation, malware
attacks, etc, and also require huge amounts of paperwork, human resources, and time. This
creates a sense of distrust among existing systems.
Some of the disadvantages are:
Long Queues during elections.
Security Breaches like data leaks, vote tampering.
Lot of paperwork involved, hence less eco-friendly and time-consuming.
Difficult for differently-abled voters to reach polling booth.
Cost of expenditure on elections is high.
Solution:
Using blockchain, voting process can be made more secure, transparent, immutable, and reliable.
How? Let’s take an example.
Suppose you are an eligible voter who goes to polling booth and cast vote using EVM (Electronic
Voting Machine). But since it’s a circuitry after all and if someone tampers with microchip, you
may never know that did your vote reach to person for whom you voted or was diverted into
another candidate’s account?
Since there’s no tracing back of your vote. But, if you use blockchain- it stores everything as a
transaction that will be explained soon below; and hence gives you a receipt of your vote (in a
form of a transaction ID) and you can use it to ensure that your vote has been counted securely.
Now suppose a digital voting system (website/app) has been launched to digitize process and all
confidential data is stored on a single admin server/machine, if someone tries to hack it or snoop
over it, he/she can change candidate’s vote count- from 2 to 22! You may never know that hacker
installs malware or performs clickjacking attacks to steal or negate your vote or simply attacks
central server.
To avoid this, if system is integrated with blockchain- a special property called immutability
protects system. Consider SQL, PHP, or any other traditional database systems. You can insert,
update, or delete votes. But in a blockchain you can just insert data but cannot update or delete.
Hence when you insert something, it stays there forever and no one can manipulate it- Thus name
immutable ledger.
But Building a blockchain system is not enough. It should be decentralized i.e if one server goes
down or something happens on a particular node, other nodes can function normally and do not
have to wait for victim node’s recovery.
So a gist of advantages are listed below:
You can vote anytime/anywhere (During Pandemics like COVID-19 where it’s impossible to
hold elections physically
Secure
Immutable
Faster
Transparent
Let’s visualize process
It is always interesting to learn things if it’s visually explained. Hence diagram given below
explains how the blockchain voting works.
According to below diagram, voter needs to enter his/her credentials in order to vote. All data is
then encrypted and stored as a transaction. This transaction is then broadcasted to every node in
network, which in turn is then verified. If network approves transaction, it is stored in a block and
added to chain. Note that once a block is added into chain, it stays there forever and can’t be
updated. Users can now see results and also trace back transaction if they want.
Figure 5.1 e-Voting System
Since current voting systems don’t suffice to security needs of modern generation, there is a need
to build a system that leverages security, convenience, and trust involved in voting process. Hence
voting systems make use of Blockchain technology to add an extra layer of security and encourage
people to vote from any time, anywhere without any hassle and makes voting process more cost-
effective and time-saving.