Professional Documents
Culture Documents
[Type here]
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
PRACTICAL - 1
Blockchain is a decentralized and distributed digital ledger technology that allows multiple
participants to maintain a shared record of transactions or information in a secure and transparent
manner.
At its core, a blockchain consists of a chain of blocks, where each block contains a list of
transactions or data. These blocks are linked to each other using cryptographic hashes, forming a
chronological
Enrollment No. pg 1
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
2/ Hash
It is a cryptographic function, used for encrypting textual data. It takes variable sized of
text as input and return fixed size string of numbers and alphabets. A tiny change in input
changes the output completely. Hash functions are uncrackable. They are at the very core of
blockchain technology, every block in blockchain has a Hash and previous Hash associated with
them. This hash is made up of all the transaction in the block, Nonce and previous Hash. If
someone adds a wrong block or changes content of some block hash of every block after it gets
changes. If they want to make sure that their block stays in the chain, they must continuously
broadcast blocks that must come after their block
3/ Block Number
Block number is a very fundamental and important property of blocks in every
blockchain. It is a sequential number that represents the position or order of a block within the
blockchain. The Block Number increased by number of blocks in any blockchain.
Enrollment No. pg 2
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Enrollment No. pg 3
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
1. Immutable
Block chain is an immutable data structure. Which means the content of the block is not editable.
If someone tries to edit or remove content the hash of the block will be changed which will led to
change Hashes of all the other block came after it.
2. Secure
Blockchain is very Secure way to make transaction. In order to make transaction one need to
have pair of private – public key pair. User uses private key to sigh the transaction and generate
signature.
3. Distributed
Blockchain is distributed ledger, which means every user has copy of the ledger. Even when few
of the copies of ledger get corrupted, as long as we have one computer with correct ledger the
system will stay available and trustable.
4. Decentralized
Rather than relying on a central authority, blockchain operates on a peer-to-peer network, where
multiple participants (nodes) validate and maintain the ledger collectively
5. Transparency
The blockchain ledger is transparent and visible to all participants within the network. Every
participant has a copy of the entire blockchain, ensuring that any changes or transactions are
visible to all...
CONCLUTION:
We have covered the definition of a block chain, block numbers, block data, nonces, hashes, and
other aspects of a blockchain that are crucial to understanding before using the technology
Enrollment No. pg 4
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
PRACTICAL - 2
Code Editor: It provides a code editor with syntax highlighting and auto- completion for
Solidity, the programming language used for writing smart contracts on Ethereum.
Debugger: Remix IDE offers a powerful debugging feature that allows developers to
step through their smart contracts, inspect variable values, and trace function calls. This
helps in identifying and resolving issues in the contract logic.
Deploy and Interact: Remix IDE enables developers to deploy their smart contracts to
various Ethereum networks directly from the IDE. It also provides a user interface for
interacting with deployed contracts, allowing users to execute contract functions and
view contract state.
Testing: The IDE includes a testing framework that allows developers to write and
execute test cases for their smart contracts. This helps in ensuring the functionality and
correctness of the contracts.
Plugin System: Remix IDE supports a plugin system that allows developers to extend its
functionality. Users can integrate additional tools, libraries, and services to enhance their
development workflow.
Enrollment No. pg 5
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
METAMASK
Metamask is a popular cryptocurrency wallet and browser extension that enables
users to interact with the Ethereum blockchain. It functions as a bridge between users'
web browsers and the Ethereum network, allowing them to manage their Ethereum
accounts, store Ether (ETH) and other ERC-20 tokens, and securely execute transactions
and interact with decentralized applications (dApps).
Wallet and Account Management: Metamask serves as a digital wallet that generates
and stores Ethereum accounts (also known as addresses) for users. Each account is
associated with a unique private key, which is encrypted and stored locally on the user's
device. Users can import or create multiple accounts within Metamask and easily switch
between them.
Secure Transaction Execution: Metamask allows users to send and receive Ether and
ERC-20 tokens securely. When initiating a transaction, Metamask prompts users to
review and confirm the transaction details before submitting it to the Ethereum network.
Users can also customize gas fees to control the speed and cost of their transactions.
Enrollment No. pg 6
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Integration with dApps: Metamask acts as a gateway for interacting with decentralized
applications (dApps) built on the Ethereum blockchain. When users access a dApp,
Metamask detects the connection and enables the interaction by providing the necessary
account and transaction information securely.
Enhanced Security Features: Metamask offers additional security features, such as the
ability to set a password for accessing the wallet, the option to export and import
accounts, and the ability to connect hardware wallets for added security.
It's worth noting that while Metamask is primarily associated with Ethereum, it has also
expanded to support other blockchain networks such as Binance Smart Chain (BSC) and
Polygon (formerly Matic Network).
Enrollment No. pg 7
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
GANACHE
Ganache is a development tool and personal Ethereum blockchain emulator
provided by Truffle Suite. It allows developers to create and deploy their own local
Ethereum network for testing and development purposes. Ganache is often used in
blockchain development workflows as it provides a convenient way to simulate the
behaviour of a real Ethereum network without the need for actual network connectivity.
Quick Network Setup: With Ganache, developers can quickly set up a local Ethereum
network with predefined accounts and pre-funded Ether balances. These accounts can be
used for testing smart contracts, executing transactions, and simulating different
scenarios.
Control over Blockchain State: Ganache allows developers to have control over the
state of the blockchain. You can start with a clean state each time you run Ganache or
load a specific snapshot of the blockchain state. This is useful for testing different
contract behaviours or reproducing specific situations.
Block Mining Control: Ganache provides control over block mining, allowing
developers to set custom block mining times or instantly mine new blocks. This allows
for more predictable testing scenarios, especially when working with time-dependent
functionalities in smart contracts.
Enrollment No. pg 8
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
framework for Ethereum that provides additional features such as smart contract
compilation, migration, and testing. Ganache is often used in conjunction with Truffle
for streamlined development workflows.
Ganache is available in two versions: Ganache CLI (Command Line Interface) and
Ganache GUI (Graphical User Interface). Ganache CLI is a command-line tool that
provides a lightweight and scriptable interface, while Ganache GUI offers a user-
friendly graphical interface for managing and interacting with the local blockchain.
CONCLUTION:
Last but not least, we learned about Ganache, which offers local host platforms that ar are
crucial and helpful when we have to carry out testing for our specific projects and applications.
Ganache is a blockchain based Etherium IDE that allows us to perform several tasks in the
solidity language of the IDE
Enrollment No. pg 9
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
PRACTICAL - 3
Enrollment No. pg 10
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Output :
Transactions:
Using Ganache:
Enrollment No. pg 11
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Transaction:
CONCLUTION:
We have successfully created a simple Solidity contract that prints "Hello World!" using
the Ethereum Remix IDE. We deployed the contract to the Ganache Truffle platform and
obtained a transaction address. This practical demonstrates the basic
steps involved in writing and deploying a Solidity contract, as well as the integration with
a local blockchain network like Ganache. By expanding upon this foundation, you can
explore and develop more complex smart contracts and decentralized applications on the
Ethereum platfo
Enrollment No. pg 12
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
PRACTICAL - 4
Code :
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7;
contract Calculate{
Enrollment No. pg 13
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Deployment:
Enrollment No. pg 14
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
CALL:
Enrollment No. pg 15
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
ETHERSCAN:
Contract: 0x81886fb6e50ce44c0f71dBd597fB45c9C043Ebe1
Enrollment No. pg 16
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
PRACTICAL-5
AIM: Deploy a smart contract for FINDING LARGEST
NUMBER OUT OF THREE NUMBERS using Java Script
VM, Injected Web3 and Web3Provider using Metamask and
Ganache.
Enrollment No. pg 17
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
Code :
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7;
contract Calculate1 {
function FindLargest(uint256 a, uint256 b, uint256 c) external returns (uint256){
if(a > b) {
if(a > c){
return a;
}
else {
if(c > b){
return c;
}
else{
return b;
}
}
}
else {
if(c > b){
return c
}
else{
return b;
}
}}}
Enrollment No. pg 18
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
DEPLOYMENT:
Enrollment No. pg 19
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th
CALL:
ETHERSCAN:
Contract : 0xb7175602a2e813a37f569bb38B03706Ed6aa1BEf
PRACTICAL-6
AIM: Create a Smart Contract for a banking application in
solidity which allows users to do the following: Mint money
into your account, Withdraw money from your account,
Send money from your account to smart contract address,
Check balance After a contract is created. deploy the
contract on Ethereum Testnet network.
CODE :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleBank {
mapping(address => uint256) public balances;
address public owner;
constructor() payable {
owner = msg.sender;
balances[address(this)] += msg.value;
}
modifier onlyOwner() {
DEPLOYMENT:
CALL:
Contract : 0x8DDEF562d218EF3c402dDa982E99EEc4f1cEE97b
PRACTICAL-7
AIM: How to build a smart contract that lets user book
rooms and pay for them with cryptocurrency.
CODE :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
contract HotelBooking{
struct room{
uint256 roomNu;
bool available;
address client;
uint256 price;
}
mapping(uint256 => bool) public availRoom;
room[] public rooms;
address private owner;
modifier onlyOwner {
require(msg.sender == owner);
;
}
constructor(uint256 _rooms , uint256 _price ){
for(uint256 i =0;i<_rooms;i++){
rooms.push(room(i+1, false, address(this), _price));
availRoom[i+1] = true;
}
owner = msg.sender;
}
function book(uint256 _room, uint256 _days) public payable{
require(availRoom[_room] == true, "This Room is already booked!");
availRoom[_room] = false;
uint256 i;
for (i = 0; i < rooms.length; i++) {
if (rooms[i].roomNu == _room) {
break;
}
}
require(i < rooms.length, "Room not found");
require(msg.value >= rooms[i].price*_days, "Payment is not enugh");
rooms[i].available = false;
rooms[i].client = msg.sender;
}
function checkOut(uint256 _room) public {
uint256 i;
for (i = 0; i < rooms.length; i++) {
if (rooms[i].roomNu == _room) {
break;
}
}
require(i < rooms.length, "Room not found");
require(msg.sender == rooms[i].client,"the address is incorrect");
rooms[i].available = true;
rooms[i].client = address(this);
availRoom[_room] = true;
}
function changePrice(uint256 _room, uint256 _price) onlyOwner public{
uint256 i;
for (i = 0; i < rooms.length; i++) {
if (rooms[i].roomNu == _room) {
break;
}
}
require(i < rooms.length, "Room not found");
rooms[i].price = _price;
}
function getPrice(uint256 _room) public view returns(uint256){
uint256 i;
for (i = 0; i < rooms.length; i++) {
if (rooms[i].roomNu == _room) {
break;
}
}
require(i < rooms.length, "Room not found");
return rooms[i].price;
}
}
DEPLOYMENT :
CALL:
Contract : 0x5a52cCB00Fa33a191a743F8c91Bf8265775e82C7
PRACTICAL-8
AIM: Deploy a smart contract using MyEtherWallet
(MEW).
CODE:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13;
contract HelloWorld {
function HelloWorldfun() public pure returns (string memory)
{
return "Hello World";
}
}
DEPLOYMENT:
CONTRACT: 0xf3758E2Eea54759D7aA073397A0EecDe8D19736d
PRACTICAL-9
AIM: Deploy the smart contract for RAFFLE DRAW
GAME.
Code :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract RaffleDraw {
address public manager;
address[] public players;
address public winner;
constructor() {
manager = msg.sender;
}
modifier onlyManager() {
DEPLOYMENT:
CONTRACT : 0x5a2BFBF00EA1aC3E249f124515d7F4898382e2eC
PRACTICAL-10
AIM: Deploy Smart Contract for E-Voting.
CODE :
// SPDX-License-Identifier: MIT
contract EVoting {
struct Voter {
bool voted;
address vote;
}
struct Candidate {
uint256 id;
string name;
uint256 voteCount;
}
address public owner;
voters[msg.sender] = Voter({
voted: true,
vote: msg.sender
});
candidates[candidateId].voteCount++;
emit Voted(msg.sender, candidateId);
}
function getWinner() public onlyOwner view returns (string memory){
require(block.timestamp >= electionEndTime, "Election is still ongoing");
uint256 winningVoteCount = 0;
string memory winningCandidate = "";
for (uint256 i = 0; i < candidates.length; i++) {
if (candidates[i].voteCount > winningVoteCount) {
winningVoteCount = candidates[i].voteCount;
winningCandidate = candidates[i].name;
}
}
return winningCandidate;
}
function getCandidates() public view returns (uint256[] memory, string[] memory) {
uint256[] memory candidateIds = new uint256[](candidates.length);
string[] memory candidateNames = new string[](candidates.length);
for (uint256 i = 0; i < candidates.length; i++) {
candidateIds[i] = candidates[i].id;
candidateNames[i] = candidates[i].name;
}
return (candidateIds, candidateNames);
}
function getVotes() public onlyOwner view returns(string[] memory, uint256[] memory)
{
DEPLOYMENT:
Contract : 0xc1daD70cD5d19ad5C54467F6Cfca6d0039f696C3