You are on page 1of 44

CERTIFICATION

This is to certify that Mr./Ms with enrollment


number has successfully completed his/her
laboratory experiments in BLOCKCHAIN LABORAROTY (203105409)
from the department of Computer Science & Engineering during the
academic year 2023-2024.

Date of Submission: ......................... Staff In charge: ........................

Head Of Department: ............................

[Type here]
FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

PRACTICAL - 1

AIM: Demonstrate Blockchain characteristics [DIT].


WHAT IS BLOCKCHAIN:

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

IMPORTANT TERMINOLOGIES RELATED TO BLOCKCHAIN:


1/ Block
Blockchain is nothing but series of blocks connected with a hash values (like linked list).
These blocks have pre-defined structure which must be followed by all the blocks in the chain.

The common structure of block is described above

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

KEY CHARACTRISTIC BLOCK CHAIN:

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.

SignFunc( message /transaction, private key ) = Signature


This signature could be used to verify the transaction.
The function uses public key of user to verify if the given transaction is indeed made by the very
same user.

VerifyFunc( message /transaction, Signature, public key ) = T/F


The private key is only available to user, so that only authorized user can make signature. Where
else the public key is available to all the users on blockchain, so that every user can verify
transaction.

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

AIM: Introduction to Ethereum tools.


REMIX IDE
Remix IDE refers to an integrated development environment (IDE) specifically designed
for developing smart contracts on the Ethereum blockchain. It is a popular tool used by
blockchain developers for writing, debugging, and deploying smart contracts. Remix IDE
provides a user- friendly interface and a set of powerful features that simplify the
development process.

Remix IDE offers various functionalities, including:

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.

Compiler: Remix IDE includes a built-in Solidity compiler, allowing developers to


compile their smart contracts directly within the IDE. It supports different Solidity
versions and provides compile-time error checking.

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).

Here are some key features and functionalities of Metamask:

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.

Browser Extension: Metamask is available as a browser extension for popular web


browsers like Chrome, Firefox, Brave, and Edge. Once installed, it integrates directly
into the browser, providing a seamless experience for interacting with Ethereum-based
applications.

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.

Token Management: Metamask supports various ERC-20 tokens, allowing users to


manage and view their token balances within the wallet users can also add custom
tokens that are not automatically detected by Metamask.

Network Customization: Metamask supports multiple Ethereum networks, including


the main Ethereum network (often referred to as the "Mainnet"), as well as various test
networks like Ropsten, Rinkeby, and Kovan. This allows users to switch between
different networks for development, testing, or accessing specific dApps on alternative
networks.

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.

Here are some key features and functionalities of Ganache:

Local Ethereum Blockchain: Ganache creates a local blockchain environment on your


computer, which runs entirely on your local machine. This allows you to interact with
the Ethereum network without the need for an internet connection or interacting with the
actual Ethereum network.

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.

Account Management: Ganache generates a set of Ethereum accounts with


corresponding private keys, which can be used for interacting with the local network.
You can import these accounts into development tools like Remix IDE or MetaMask for
testing smart contracts or deploying dApps.

Transaction Logging and Visualization: Ganache provides detailed logs of each


transaction and event occurring on the local network. These logs can be helpful for
debugging and understanding the interactions between smart contracts during
development.

Integration with Development Tools: Ganache seamlessly integrates with other


popular blockchain development tools like Truffle Suite. Truffle is a development

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

AIM: Deploy a smart contract for printing “Hello World”


using JavaScript VM, Injected Web3 and Web3Provider
using Metamask and Ganache.

Steps to perform this task:


- Step:1 open the url https://remix.ethereum.org/
- Step:2 Click on file explorer new file under contracts
- Step:3 Write simple solidity code to print HelloWorld contract.
- Step: 4 Compile the code with appropriate compiler, You could see your “Hello
World” contract.
- Step:5 Once the compilation done. Go to https://metamask.io/ and download
extension, create account.
- Step: 6 Go to https://sepoliafaucet.com/ create account and add ethers to your
wallet.
- Step: 7 Go to Remix IDE, select appropriate environment and deploy the contract.
- Step: 8 Go to https://etherscan.io/ website to view the created block.

Code which have to be applied in the solidity IDE is here :


Code :

// SPDX-License-Identifier: MIT pragma solidity ^0.8.13;


contract HelloWorld {
function HelloWorldfun() public pure returns (string memory)
{
return "Hello World";
}
}

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

AIM: Deploy a smart contract for arithmetic operations


using Java Script VM, Injected Web3 and Web3Provider
using Metamask and Ganache.

Steps to perform this Task:


- Step 1: open the url https://remix.ethereum.org/
- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate contract
- Step 4: Compile your ‘Calculate’ contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can
deploy and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue
with transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan
or any other block explorer, via contract address.
- Step 7: Call the function “add” of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan.

Code :
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7;

contract Calculate{

function add(uint256 a, uint256 b) external returns(uint256){


return a+b;
}

function sub(uint256 a, uint256 b) external returns(uint256){


return a-b;
}

function mul(uint256 a, uint256 b) external returns(uint256){


return a*b;
}

function div(uint256 a, uint256 b) external returns(uint256){


return a/b;
}
}

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.

Steps to perform this Task:

- Step 1: open the url https://remix.ethereum.org/


- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate1 contract
- Step 4: Compile your ‘Calculate1’ contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can
deploy and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue
with transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan
or any other block explorer, via contract address.
- Step 7: Call the function “FindLargest” of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan

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

Enrollment No. 200305105015 pg 20


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

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.

Steps to perform this Task:

- Step 1: open the url https://remix.ethereum.org/


- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate1 contract
- Step 4: Compile your ‘HotelBooking contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can
deploy and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue
wit transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan
or any other block explorer, via contract address.
- Step 7: Call the function any function of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan.

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() {

Enrollment No. 200305105015 pg 21


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

require(msg.sender == owner, "Only the owner can perform this action");


;
}
function mint(uint256 amount) public {
require(amount > 0, "Amount must be greater than 0");
require(address(this).balance >= amount, "Insufficient contract balance");
balances[msg.sender] += amount;
balances[address(this)] -= amount;
}
function withdraw(uint256 amount) public payable{
require(amount > 0, "Amount must be greater than 0");
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}
function sendToSmartContract(address smartContractAddress, uint256 amount) public payable {
require(amount > 0, "Amount must be greater than 0");
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
(bool success,) = payable(smartContractAddress).call{value: amount}("");
}
function checkBalance() public view returns (uint256) {
return balances[msg.sender];
}
function contractBalance() public view onlyOwner returns (uint256) {
return address(this).balance;
}
}

Enrollment No. 200305105015 pg 22


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

DEPLOYMENT:

Enrollment No. 200305105015 pg 23


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

CALL:

Contract : 0x8DDEF562d218EF3c402dDa982E99EEc4f1cEE97b

Enrollment No. 200305105015 pg 24


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

PRACTICAL-7
AIM: How to build a smart contract that lets user book
rooms and pay for them with cryptocurrency.

Steps to perform this Task:

- Step 1: open the url https://remix.ethereum.org/


- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate1 contract
- Step 4: Compile your ‘HotelBooking contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can
deploy and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue
wit transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan
or any other block explorer, via contract address.
- Step 7: Call the function any function of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan.

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;

Enrollment No. 200305105015 pg 25


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

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) {

Enrollment No. 200305105015 pg 26


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

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;
}
}

Enrollment No. 200305105015 pg 27


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

DEPLOYMENT :

Enrollment No. 200305105015 pg 28


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

CALL:

Enrollment No. 200305105015 pg 29


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

Contract : 0x5a52cCB00Fa33a191a743F8c91Bf8265775e82C7

Enrollment No. 200305105015 pg 30


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

PRACTICAL-8
AIM: Deploy a smart contract using MyEtherWallet
(MEW).

Steps to perform this Task:

- Go to the MyEtherWallet website (https://www.myetherwallet.com/) and


ensure you are on the official, secure website. Double-check the URL to
avoid phishing sites.
- If you don't have a wallet already, you can create one using MEW. Make
sure to keep your private key/Keystore file and password safe.
- Ensure that your wallet has enough Ether (ETH) to cover the gas fees for
contract deployment.
- On the MEW website, click "Access My Wallet" and choose your preferred
method for accessing your wallet (e.g., private key, Keystore file, or
hardware wallet). Enter the required information to unlock your wallet.
- Once you're logged in, navigate to the "Contracts" tab on the MEW
interface.
- You can choose an existing contract to deploy by entering its address and
ABI (Application Binary Interface), or you can create your own custom
contract by pasting the Solidity code.
- Specify the gas price and gas limit. The gas price determines how quickly
your transaction will be processed, while the gas limit sets the maximum
amount of gas you're willing to use. Be mindful of the cost.
- Click the "Deploy Contract" button. MEW will generate a transaction for
the contract deployment.
- Review the transaction details, including gas cost and contract parameters.
If everything looks correct, click "Yes, I am sure! Make transaction" to
confirm. You may be asked to sign the transaction using your wallet's
private key or hardware wallet.
- After submitting the transaction, you'll need to wait for it to be mined and
confirmed on the Ethereum blockchain. You can track the progress of the
transaction using an Ethereum blockchain explorer.
- Once the contract is successfully deployed, you'll receive a transaction
confirmation, and the contract address will be displayed. Make sure to save
this address for future interactions with your contract.

Enrollment No. 200305105015 pg 31


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

CODE:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13;
contract HelloWorld {
function HelloWorldfun() public pure returns (string memory)
{
return "Hello World";
}
}

DEPLOYMENT:

Enrollment No. 200305105015 pg 32


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

CONTRACT: 0xf3758E2Eea54759D7aA073397A0EecDe8D19736d

Enrollment No. 200305105015 pg 33


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

PRACTICAL-9
AIM: Deploy the smart contract for RAFFLE DRAW
GAME.

Steps to perform this Task:


- Step 1: open the url https://remix.ethereum.org/
- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate1 contract
- Step 4: Compile your ‘RaffleDraw contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can deploy
and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue wit
transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan or any
other block explorer, via contract address.
- Step 7: Call the function any function of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan.

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() {

Enrollment No. 200305105015 pg 34


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

require(msg.sender == manager, "Only the manager can perform this action");


;
}
function enter() public payable {
require(msg.value > 100 wei, "Minimum entry fee is 0.01 ether");
players.push(msg.sender);
}
function random() private view returns (uint) {
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
}
function pickWinner() public onlyManager returns(address){
require(players.length > 0, "There are no participants");
uint index = random() % players.length;
winner = players[index];
// Transfer the contract balance to the winner.
// payable(winner).transfer(address(this).balance);
payable(winner).send(address(this).balance);
// Reset the list of players for the next round.
players = new address[](0);
return winner;
}
function getPlayers() public view returns (address[] memory) {
return players;
}

Enrollment No. 200305105015 pg 35


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

DEPLOYMENT:

Enrollment No. 200305105015 pg 36


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

CONTRACT : 0x5a2BFBF00EA1aC3E249f124515d7F4898382e2eC

Enrollment No. 200305105015 pg 37


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

PRACTICAL-10
AIM: Deploy Smart Contract for E-Voting.

Steps to perform this Task:


- Step 1: open the url https://remix.ethereum.org/
- Step 2: Click on file explorer new file under contracts
- Step 3: write simple solidity code to create Calculate1 contract
- Step 4: Compile your ‘EVoting’ contract using Remix compiler.
- Step 5: Once the compilation done, select Injected Metamask. This way you can deploy
and communicate with contracts with your metamask wallet.
- Step 6: Click on deployed contract. TheMetamask window will appear, continue wit
transaction.
- Step 7: After the transaction is completed you can see you contract on etherscan or any
other block explorer, via contract address.
- Step 7: Call the function any function of the contract via Remix.
- Step 8: You can see all the transaction performed on contract using etherscan.

CODE :
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract EVoting {
struct Voter {
bool voted;
address vote;
}
struct Candidate {
uint256 id;
string name;
uint256 voteCount;
}
address public owner;

Enrollment No. 200305105015 pg 38


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

mapping(address => Voter) public voters;


Candidate[] private candidates;
uint256 public electionEndTime;
event Voted(address indexed voter, uint256 candidateId);
constructor(string[] memory candidateNames, uint256 durationInMinutes) {
owner = msg.sender;
electionEndTime = block.timestamp + (durationInMinutes * 1 minutes);
for (uint256 i = 0; i < candidateNames.length; i++) {
candidates.push(Candidate({
id: i,
name: candidateNames[i],
voteCount: 0
}));
}
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can perform this action");
;
}
modifier electionNotEnded() {
require(block.timestamp < electionEndTime, "Election has ended");
;
}
modifier hasNotVoted() {
require(!voters[msg.sender].voted, "You have already voted");
;
}
function vote(uint256 candidateId) public electionNotEnded hasNotVoted {
require(candidateId >= 0 && candidateId < candidates.length, "Invalid candidate
ID");

Enrollment No. 200305105015 pg 39


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

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)
{

Enrollment No. 200305105015 pg 40


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

uint256[] memory candidateVotes = new uint256[](candidates.length);


string[] memory candidateNames = new string[](candidates.length);
for (uint256 i = 0; i < candidates.length; i++) {
candidateVotes[i] = candidates[i].voteCount;
candidateNames[i] = candidates[i].name;
}
return (candidateNames, candidateVotes);
}
}

DEPLOYMENT:

Enrollment No. 200305105015 pg 41


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

Enrollment No. 200305105015 pg 42


FACULTY OF ENGINEERING AND TECHNOLOGY
BLOCKCHAIN LABORAROTY (203105409)
B.Tech (CSE) Year: 4th Sem: 7th

Contract : 0xc1daD70cD5d19ad5C54467F6Cfca6d0039f696C3

Enrollment No. 200305105015 pg 43

You might also like