0% found this document useful (0 votes)
9 views23 pages

B.E Report BL LAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

B.E Report BL LAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

REAL ESTATE BUY-SELL PLATFORM

USING BLOCKCHAIN
By

Name of Students: Class & Roll No:

Yash Sonar BE-5-38


Harsh Dhariya BE-5-43
Kartik Patel BE-5-22

Guide
Prof. Aruna Kadam

Department of Information Technology


Shah & Anchor Kutchhi Engineering College, Mumbai
2023-2024

1
APPROVAL FOR BLOCKCHAIN MINI-PROJECT REPORT FOR
FINAL YEAR SEMESTER VIII

BLOCKCHAIN LAB

This project report entitled Real Estate Buy-Sell Platform using


BlockChain Technology by Yash Sonar, Harsh Dhariya and Kartik Patel is
approved in partial fulfilment of the requirement for the BLOCKCHAIN Lab
of Final Year Engineering.

Examiners

1.__________________________

2. __________________________

Guide

1.__________________________

Date:

2
Abstract

Smart contracts deployed on blockchain technology have demonstrated significant potential in


revolutionizing various industries by automating processes and ensuring transparency,
security, and trust. In this project, we present the development and implementation of a smart
lottery contract system built on a blockchain platform. The primary objective of our project is
to create a secure and transparent lottery system that leverages blockchain's immutable ledger
and smart contract capabilities. We aim to eliminate the need for intermediaries, reduce fraud,
and enhance the integrity of lottery operations. Our smart lottery contract system utilizes
Ethereum blockchain due to its robustness, widespread adoption, and support for smart contract
execution. The system incorporates several key features, including participant registration,
ticket issuance, random number generation, winner selection, and prize distribution, all
governed by self-executing smart contracts. To ensure fairness and transparency, the random
number generation process employs cryptographic techniques to produce unpredictable
outcomes, thus preventing any manipulation. Additionally, participants can verify the fairness
of the lottery by auditing the smart contract code and blockchain transactions. Moreover, our
smart lottery contract system enhances security by eliminating centralized control, reducing
the risk of tampering or manipulation by any single entity. Each transaction and operation is
recorded on the blockchain, providing an immutable and transparent audit trail.

3
Contents

Chapter Contents Page No.

1 Introduction 6

1.1 Introduction to Domain/Area and Motivation 6

1.2 Problem Statement 6

1.3 Proposed Solution 7

1.4 Organization of the Report 7

2 System design 8

3 Implementation and Results 10

4 Conclusion 22

5 References 23

4
List of Figures

Fig. No. Figure Caption Page No.

1 Block Diagram for the system 8

2 Flowchart of the working system 10

3 Account 1 is owner of contract 18

4 Account 1 participating in Lottery 18

5 Account 2 participating in Lottery 19

6 Only owner can pick the winner 19

7 Picking of Winner 20

8 Displaying winner address 20

9 Winner claiming the prize 21

5
Chapter 1
Introduction

1.1 Introduction to Domain/Area and Motivation

Lotteries have been a prevalent form of gambling and fundraising for centuries, with
governments, organizations, and individuals utilizing them for various purposes. However,
traditional lottery systems often suffer from issues such as lack of transparency, susceptibility
to fraud, and centralized control, leading to distrust among participants and stakeholders.
The motivation behind our project stems from the need to address these shortcomings and
revolutionize lottery systems using emerging technologies. By leveraging blockchain
technology and smart contracts, we aim to create a transparent, secure, and decentralized lottery
system that fosters trust and integrity among participants. This project seeks to harness the
potential of blockchain to enhance transparency, fairness, and efficiency in lottery operations,
ultimately benefiting participants, organizations, and society as a whole.

1.2 Problem Statement

Traditional lottery systems are plagued by various issues, including lack of transparency,
susceptibility to fraud, and reliance on centralized authorities. These shortcomings undermine
trust and integrity, leading to dissatisfaction among participants and stakeholders. Moreover,
the absence of a secure and transparent mechanism for conducting lotteries hampers the
potential for widespread adoption and acceptance of such systems. In light of these challenges,
there is a pressing need for a solution that addresses the shortcomings of traditional lottery
systems while leveraging emerging technologies to enhance transparency, security, and trust.
Blockchain technology, with its decentralized and immutable ledger, coupled with smart
contracts' self-executing capabilities, presents a promising avenue for revolutionizing lottery
operations.

6
1.3 Proposed Solution

Smart Lottey contract provides the functionalities of participating in lottery using Metamask
account and allowing only the owner of the contract to pick the winner. These functionalities
are provided to the user using metamask. Here, React app is connected with the MetaMask on
the web browser and the MetaMask accounts are imported with ethers from faucets.chain.link
which provides the ethers for carrying out the transactions. So as soon as the user tries
performing the above mentioned functionalities, the metamask needs to be logged in and the
user needs to confirm the transaction to get it done. As soon as the user clicks on confirm, the
respective operation gets performed and the amount gets debited/credited from the metamask
account.

1.4 Organization of the Report

The rest of the report is organized as follows. Chapter 2 presents the summary of the literature
review carried out. Chapter 3 discusses the system design of the proposed model. In Chapter
4, we present the results and implementation steps for the system. And finally, Chapter 5
includes the conclusion followed by references.

7
Chapter 2
System design

Fig 1: System Design

The above diagram Fig 1 shows the system design of the Smart Lottery Contract.
The user needs to be logged in with the metamask in order to carry out further operations. Once
the user is successfully logged in he/she will be able to enter lottery and claim prize if winner.

Hardware and Software Requirements


Software:
1) VsCode
2) Metamask.
3) Node Package Manager.
4) Windows 10 and above.

8
Application Areas of Project
● Government Lotteries
● Event Ticketing
● Crowdfunding Campaigns
● Charitable organizations

9
Chapter 3
Implementation and results

Flowchart

Fig 2: Flowchart of implementation

In Fig 4, The user needs to log in with a metamask in order to carry out the Lottery functionalities.
Once logged in, he/she will be able to select the required operation. After the operation is selected,
the user needs to provide the input to get the operation performed.

10
Code

Lottery.sol
pragma solidity ^0.8.0;
// SPDX-License-Identifier: UNLICENSED
contract Lottery{
address public manager;
address payable[] public players; // in order to send ether to or recieve from contract to account
or likewise
address payable winner;
bool public isComplete;
bool public claimed;
constructor() {
manager = msg.sender;
isComplete = false;
claimed = false;
}
modifier onlyManager(){
require(msg.sender == manager);
_;
}
function getManager() public view returns(address){
return manager;
}
function getWinner() public view returns(address){
return winner;
}
function status() public view returns (bool) {
return isComplete;
}
function enter() public payable{
require(msg.value >= 0.001 ether);
require(!isComplete);
players.push(payable(msg.sender));
}
function pickWinner() public onlyManager {
require(players.length > 0);
require(!isComplete);
winner = players[randomNumber() % players.length];
isComplete = true;
}
function randomNumber() private view returns (uint){

11
return uint(keccak256(abi.encodePacked(block.prevrandao, block.timestamp,
players.length)));
}
function claimPrize() public {
require(msg.sender == winner);
require(isComplete);
winner.transfer(address(this).balance);
claimed = true;
}
function getPlayers() public view returns (address payable[] memory) {
return players;
}
}
Home.js
import React, { useState, useEffect } from "react";
import { ethers } from 'ethers';
import constants from './constants';

function Home() {
const [currentAccount, setCurrentAccount] = useState("");
const [contractInstance, setContractInstance] = useState('');
const [status, setStatus] = useState(false);
const [isWinner, setIsWinner] = useState('');

const [isOwnerConnected, setisOwnerConnected] = useState(false);


const [owner, setOwner] = useState('');

useEffect(() => {
const fetchData = async () => {
if (contractInstance) {
const status = await contractInstance.status();
setStatus(status);
const winner = await contractInstance.getWinner();
setIsWinner(winner);
const owner = await contractInstance.getManager();
setOwner(owner);
if (owner === currentAccount) {
setisOwnerConnected(true);
} else {
setisOwnerConnected(false);
}
}
};

fetchData();

12
}, [contractInstance, currentAccount]);

useEffect(() => {

const loadBlockchainData = async () => {


if (typeof window.ethereum !== 'undefined') { // metamask is installed
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []); // <- this promps user to connect
metamask

// window.ethereum.enable()

try {
const signer = provider.getSigner();
const address = await signer.getAddress();
console.log(address);
setCurrentAccount(address);
window.ethereum.on('accountsChanged', (accounts) => {
setCurrentAccount(accounts[0]);
console.log(currentAccount)
})
} catch (err) {
console.log(err);
}
}
else {
alert('Please install Metamask to use this application')
}
};

const contract = async () => {


const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer = provider.getSigner();
const contractIns = new ethers.Contract(constants.contractAddress,
constants.contractAbi, signer);
setContractInstance(contractIns);
// const status = await contractInstance.status();
// setStatus(status);
const winner = await contractInstance.getWinner();

13
if (winner === currentAccount) {
setIsWinner(true);
}
else {
setIsWinner(false);
}

loadBlockchainData();
contract();
}, [currentAccount])

const enterLottery = async () => {


const amountToSend = ethers.utils.parseEther('0.001');
const tx = await contractInstance.enter({ value: amountToSend });
await tx.wait();
}
const claimPrize = async () => {
const tx = await contractInstance.claimPrize();
await tx.wait();
}

return (
<div className="container">
<h1>Lottery Page</h1>
<div className="button-container">
{
status ? (isWinner ? (<button className="enter-button" onClick={claimPrize}>
Claim Prize </button>) : (<p>You are not the winner</p>)) : (<button className="enter-button"
onClick={enterLottery}> Enter Lottery </button>)
}
</div>
</div>
)
}
export default Home;

PickWinner.js
import React, { useState, useEffect } from "react";
import { ethers } from 'ethers';
import constants from './constants';
function PickWinner() {

14
const [owner, setOwner] = useState('');
const [contractInstance, setContractInstance] = useState('');
const [currentAccount, setCurrentAccount] = useState('');
const [isOwnerConnected, setisOwnerConnected] = useState(false);
const [winner, setWinner] = useState('');
const [status, setStatus] = useState(false);

useEffect(() => {
const fetchData = async () => {
if (contractInstance) {
const status = await contractInstance.status();
setStatus(status);
const winner = await contractInstance.getWinner();
setWinner(winner);
const owner = await contractInstance.getManager();
setOwner(owner);
if (owner === currentAccount) {
setisOwnerConnected(true);
} else {
setisOwnerConnected(false);
}
}
};

fetchData();
}, [contractInstance, currentAccount]);
useEffect(() => {
const loadBlockchainData = async () => {
if (typeof window.ethereum !== 'undefined') { // metamask is installed
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []); // <- this promps user to connect
metamask

// window.ethereum.enable()

try {
const signer = provider.getSigner();
const address = await signer.getAddress();
console.log(address);
setCurrentAccount(address);
window.ethereum.on('accountsChanged', (accounts) => {
setCurrentAccount(accounts[0]);
console.log(currentAccount)
})

15
} catch (err) {
console.log(err);
}
}
else {
alert('Please install Metamask to use this application')
}
};

const contract = async () => {


const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer = provider.getSigner();
const contractIns = new ethers.Contract(constants.contractAddress,
constants.contractAbi, signer);
setContractInstance(contractIns);
// const status = await contractInstance.status();
// setStatus(status);
const winner = await contractInstance.getWinner();
setWinner(winner);
const owner = await contractInstance.getManager();
setOwner(owner);
if (owner === currentAccount) {
setisOwnerConnected(true);
}
else {
setisOwnerConnected(false);
}

loadBlockchainData();
contract();
}, [currentAccount])

const pickWinner = async () => {


const tx = await contractInstance.pickWinner();
await tx.wait();
}

return (
<div className='container'>
<h1>Result Page</h1>
<div className='button-container'>

16
{status ? (<p>Lottery Winner is : {winner}</p>) :
(isOwnerConnected ? (<button className="enter-button" onClick={pickWinner}>
Pick Winner </button>) :
(<p>You are not the owner</p>))

}
</div>
</div>
)

}
export default PickWinner;

17
Output:

Fig 3: Shows the home page of the Smart Lottery Contract where Account 1 can carry out the
its operations as it is the owner of contract and also shows the transaction carried out via
Metamask

Fig 4: Shows the transaction carried out via Metamask from Account 1

18
Fig 5: Shows the transaction carried out via Metamask from Account 2

Fig 6: Shows that Account 2 is not the owner, so it cannot pick the winner

19
Fig 7: Shows the transaction carried out via Metamask after picking the winner

Fig 8: Shows the address of the account who is the winner

20
Fig 9: Shows the transaction carried out via Metamask for Account 1 after claiming the prize

21
Chapter 4
Conclusion
In conclusion, the development and implementation of a smart lottery contract project using
blockchain technology hold significant promise for revolutionizing lottery systems across
various domains. Through our project, we have demonstrated the feasibility and benefits of
leveraging blockchain's decentralized ledger and smart contract capabilities to address the
shortcomings of traditional lottery systems. By integrating blockchain technology, we have
tackled key challenges such as transparency, security, and trust, which are paramount in
lottery operations. The immutable nature of blockchain ensures transparent and auditable
lottery transactions, fostering trust among participants and stakeholders. Moreover, the use of
smart contracts enables automated and self-executing lottery processes, eliminating the need
for intermediaries and reducing the risk of fraud or manipulation.

22
References

[1] A. Dixit, A. Trivedi and W. W. Godfrey, "Blockchain Based Secure Lottery Platform by
Using Smart Contract," 2022 IEEE 6th Conference on Information and Communication
Technology (CICT), Gwalior, India, 2022, pp. 1-5, doi: 10.1109/CICT56698.2022.9997830.

[2] A. Hire, H. Lanjewar, P. Haridas, M. Jadhav and M. Rane, "Decentralized Lottery Using
Blockchain," 2023 3rd International Conference on Pervasive Computing and Social
Networking (ICPCSN), Salem, India, 2023, pp. 1035-1041, doi:
10.1109/ICPCSN58827.2023.00176.

[3] R. Bezuidenhout, W. Nel and J. M. Maritz, "Permissionless Blockchain Systems as Pseudo-


Random Number Generators for Decentralized Consensus," in IEEE Access, vol. 11, pp.
14587-14611, 2023, doi: 10.1109/ACCESS.2023.3244403.

[4] Nikhil, S. Panday, A. Saini and N. Gupta, "Instigating Decentralized Apps with Smart
Contracts," 2022 International Conference on Advances in Computing, Communication and
Applied Informatics (ACCAI), Chennai, India, 2022, pp. 1-5, doi:
10.1109/ACCAI53970.2022.9752568.

23

You might also like