Mini Project
Mini Project
USING BLOCKCHAIN
A PROJECT REPORT
Submitted by
VISHNU RAM V
(210419104185)
SUDHARSAN S
(210419104167)
of
BACHELOR OF ENGINEERING
in
SIGNATURE SIGNATURE
The project report submitted for the viva voce held on ………….
I thank the almighty, for the blessings that have been showered upon me to
bring forth the success of the project. I would like to express my sincere gratitude
to our chairman Mr.I.XYYX, vice chairman Mr.I.Yyyyyyyy and our secretary
Mr.I.DDDDDD for providing us with an excellent infrastructure and necessary
resources to carry out this project and I extend my gratitude to ourprincipal Dr.
I.VVVVVVV, for his constant support to my work.
I express our deep sense of thanks to all faculty members in my department for
their cooperation and interest shown at every stage of our endeavor in making a
project work success.
Last but not least, our sincere thanks to our lovely parents and friends who
had been the constant source of our strength throughout our life.
iii
ABSTRACT
for so long. But with the growing technologies, the security and resources on
which supports the idea of a network managing its own security and resources.
of the people for a particular issue or topic. These polls must be created and
conducted in a secure way so that the polls remain unbiased from any kind of
malicious users. Since Blockchain can secure any kind of data transmission, it is
extremely useful for voting systems since the value of votes cannot be
create a poll, which is then displayed to all the users. Any user can cast their
vote to any poll in the system and the final results are achieved in a transparent
iv
TABLE OF CONTENTS
CHAPTER TITLE PAGE
NO NO
ABSTRACT iv
LIST OF FIGURES vii
LIST OF TABLES viii
LIST OF ABBREVIATION ix
1 INTRODUCTION 1
1.1 Scope of the project 2
1.2 Objective of the project 2
1.3 Review Summary 2
2 RELATED ARTICLES 3
2.1 Introduction 3
2.1 Introduction 3
v
4 PROPOSED METHODOLOGY 10
4.1 Methodology 10
5 SYSTEM SPECIFICATION 14
5.1 Software Requirement 14
5.1.1 NodeJs 14
5.1.2 NPM 14
5.1.3 ReactJs 15
5.1.4 Solidity 15
5.1.5 Truffle Suite 15
5.1.6 Metamask 15
APPENDIX-1 REFERENCES 28
vi
LIST OF FIGURES
vii
LIST OF TABLES
viii
LIST OF ABBREVATIONS
S. NO ABBREVATION EXPANSION
ix
CHAPTER 1
INTRODUCTION
Polls tell us what proportion of a population has a specific viewpoint. They do not
explain why respondents believe as they do or how to change their minds. This is the
work of social scientists and scholars. Polls are simply a measurement tool that tell us
how a population thinks and feels about any given topic. This can be useful in helping
different cultures understand one another because it gives the people a chance to speak
for themselves instead of letting only vocal media stars speak on behalf of all. This is
where the concept of Opinion polls come in. Opinion polling gives people who do not
usually have access to express their feelings on why they choose what they choose. A
nonbiased opinion poll is a type of survey or inquiry designed to measure the public’s
views regrading a particular topic or series of topics. Trained interviewers ask questions
of people chosen at random from the population being measured. Responses are given,
and interpretations are made based on the results. It is important in a random sample that
everyone in the population being studied has an equal chance of participating.
The existing polling systems or voting systems are vulnerable to various security attacks
like vote alteration and manipulation, malware attacks, DDoS attacks, etc.
With high security and transparency provisions, Blockchain is being widely used in
supply chain management systems, healthcare, payments, business, IOT, voting systems,
etc. Using blockchain, voting can be made more secure, transparent, immutable, and
reliable. Blockchain stores every transaction, so they users can track back their votes. In
blockchain, you can just insert data but cannot update or delete. Hence when you insert
something it stays on immutable forever, I.e., nobody can change it. Blockchain systems
also offer decentralization. If one server goes down or something happens on a particular
node, other nodes can function normally can do not have to wait for victim node’s
recovery.
1
2
SCOPE OF THE PROJECT
Polling systems should work towards opinion gathering rather than measuring
the majority in a population. Blockchain based voting systems provides many
advances in the voting process such as, transparent polling process, efficient vote
counting, immutable votes, protection from data leaks and many more. In our
project, we let the users express their opinion along with their votes. And with the
help of blockchain technology, we aim towards a completely secure and
decentralized polling system, which works in the most transparent manner.
REPORT SUMMARY
The project report is organized as follows: the chapter 2 narrates the related
work done in this Decentralized polling system, chapter 3 explains the fundamentals and
methodologies, chapter 4 depicts the architecture and design of the proposed
methodology, chapter 5 discuss the system implementation , software and hardware
requirements, chapter 6describes the implementation of blockchain ledger and
creating user interface for Decentralized polling system, the chapter 7 details the
conclusion and future work of the Decentralized and the last section provides the
references and appendix.
3
CHAPTER 2
RELATED ARTICLES
INTRODUCTION
A trusted electronic election system requires that all the involved information must
go public, that is, it focuses not only on transparency but also privacy issues. In other
words, each ballot should be counted anonymously, correctly, and efficiently.
Researchers from National Taiwan University proposed a lightweight E-voting
system for voters to minimize their trust in the authority or government. They ensure
the transparency of election by putting all message on the blockchain, in the
meantime, the privacy of individual voter is protected via an efficient and effective
ring signature mechanism. Besides, the attractive self-tallying feature is also built in
our system, which guarantees that everyone who can access the blockchain network
is able to tally the result on his own, no third party is required after voting phase.
More importantly, they ensure the correctness of voting results and keep the gas cost
of individual participant as low as possible, at the same time. Clearly, the pre-
described characteristics make our system more suitable for large-scale election.
5
CHAPTER 3
RELATED WORK
Electronic Voting
Decentralization
In blockchain, decentralization refers to the transfer of control and decision-making
from a centralized entity (individual, organization, or group thereof) to a distributed
network. Decentralized networks strive to reduce the level of trust that participants must
place in one another, and deter their ability to exert authority or control over one another
in ways that degrade the functionality of the network.
Decentralization is not a new concept. When building a technology solution,
three primary network architectures are typically considered: centralized, distributed,
and decentralized. While blockchain technologies often make use of decentralized
networks, a blockchain application itself cannot be categorized simply as being
6
decentralized or not. Rather, decentralization is a sliding scale and should be applied to
all aspects of a blockchain application. By decentralizing the management of and access
to resources in an application, greater and fairer service can be achieved.
Decentralization typically has some tradeoffs such as lower transaction throughput, but
ideally, the tradeoffs are worth the improved stability and service levels they produce.
Blockchain
A blockchain is essentially a shared, immutable digital ledger of transactions that
is duplicated and distributed across the entire network of computer systems on the
blockchain. Each block in the chain contains a number of transactions, and every time
a new transaction occurs on the blockchain, a record of that transaction is added to
every participant’s ledger. The decentralized database managed by multiple
participants is known as Distributed Ledger Technology (DLT).
Blockchain is a type of DLT in which transactions are recorded with an immutable
cryptographic signature called a hash.
7
NEAR Protocol
NEAR is a Layer-1 blockchain solution built for an ecosystem’s underlying base
network and infrastructure. Bitcoin and Ethereum are examples of some other Layer-1
blockchains. These blockchains finalize and validate transactions as well as secure the
network from malicious behavior by incentivizing validators with rewards. In this case,
validators are rewarded with NEAR cryptocurrency tokens.
NEAR is a collective, a foundation, and a development platform built on a new
layer-one blockchain.
NEAR runs in concert with Ethereum, Polkadot, Cosmos, and more, allowing
for the free flow of assets and communication between networks for the betterment of
all.
NEAR is a development platform build on a sharded, proof-of-stake, layer-one
blockchain designed for usability.
8
Smart Contract
A "smart contract" is simply a program that runs on the blockchain. It's a
collection of code (its functions) and data (its state) that resides at a specific address on
the Ethereum blockchain.
Smart contracts are a type of account. This means they have a balance and they can
send transactions over the network. However, they're not controlled by a user, instead
they are deployed to the network and run as programmed. User accounts can then
interact with a smart contract by submitting transactions that execute a function defined
on the smart contract. Smart contracts can define rules, like a regular contract, and
automatically enforce them via the code. Smart contracts cannot be deleted by default,
and interactions with them are irreversible.
Blockchain Wallet
A blockchain wallet is a digital wallet that allows users to store and manage their
Bitcoin, Ether, and other cryptocurrencies. A blockchain wallet allows transfers in
cryptocurrencies and the ability to convert them back into a user's local currency.
Transactions are secure, as they are cryptographically signed. The wallet is
accessible from web devices, including mobile ones, and the privacy and identity of the
user are maintained. So, a blockchain wallet provides all the features that are necessary
for safe and secure transfers and exchanges of funds between different parties.
9
10
Meta Transactions
This is a fancy name for a simple idea: a third-party (called a relayer) can send
another user’s transactions and pay themselves for the gas cost. In this scheme, users
sign messages (not transactions) containing information about a transaction they would
like to execute. Relayers are then responsible for signing valid transactions with this
information and sending them to the network, paying for the gas cost. A base contract
preserves the identity of the user that originally requested the transaction. In this way,
users can interact directly with smart contracts without needing to have a wallet or own
currency.
This means that, in order to support meta transactions in your application, you
need to keep a relayed process running - or leverage a decentralized relayer network.
11
CHAPTER 4
PROPOSED
METHODOLOGY
METHODOLOGY
This section presents the methodology used for the creating the decentralized polling
system. A solidity directory is initialized and the avalanche details, avalanche wallet
are collected and store the mnemonics in an “.env” file. Smart contracts are created
using solidity and one Main contract is created for maintaining all sub contacts. The
smart contracts and the main contract created needs to be deployed to the blockchain.
This is done with the help of migrations. We fund the account and run these
migrations. A user interface for polling is built using React framework. We have 3
main components in user interface: One for creating elections, one for viewing the
active elections and one for viewing specific election and casting the vote.
12
Fig. 4.1 Process of Development
13
In our application, Individual users can login and create polls. When the user
creates a poll or votes on a poll, they’ll be asked to sign their transaction, once they
sign the transaction the transaction_Id, user_signature and timestamp is sent to the
smart contract for the specific poll. Each individual poll has its own smart contract and
the smart contract which is written in solidity executes itself and deployed the
transaction into the avalanche network.
In the avalanche network the transaction is broadcasted to different nodes present in the
network and upon receiving the details of the transaction each node performs an
operation to verify the transaction with the transaction_Id and
user_signature. Verified transactions are then added to the chain. After the vote is
added to the chain, the total transactions are processed and the results are immediately
sent to the front-end. The vote count is displayed simultaneously to all users and the
final results are displayed after the time of the poll runs out.
SYSTEM SPECIFICATION
Software Requirement
NodeJS
15
NPM
16
ReactJs
ReactJS tutorial provides basic and advanced concepts of ReactJS. Currently, ReactJS
is one of the most popular JavaScript front-end libraries which has a strong foundation
and a large community.
ReactJS is a declarative, efficient, and flexible JavaScript library for building
reusable UI components. It is an open-source, component-based front-end library
which is responsible only for the view layer of the application. It was initially
developed and maintained by Facebook and later used in its products like WhatsApp
& Instagram.
Solidity
Truffle Suite
Metamask
18
Hardware Requirement
Processor IntelCore
Operating System Windows 10 (64-bit)
RAM 4 GB
Installation procedure
19
2. Install ReactJs using the following command:
ReactJs is the most popular front-end development framework . TensorFlow is the most
popular AI software library and is created/maintained by Google. Keras is another
highly popular & high-level neural networks API, written in Python and capable of
running on top of TensorFlow. It was developed with a focus on enabling fast
experimentation.and is created/maintained by Facebook. It is a component-based
framework where all the UI parts are built as components. It was developed with a
focus on enabling fast experimentation.
Truffle suite is collection for software like ganache, truffle, and drizzle. It is used to
create a local Ethereum virtual machine (EVM), where we can deploy our smart
contract for testing. It is a development environment, testing framework and asset
pipeline for Ethereum, aiming to make life a developer easier.
20
5. In the dashboard we can see the wallet address, copy the address and add
some fund by pasting your address in faucet.avax.network.
21
22
Smart Description
• Poll is a Solidity contract that lets us view the name and description, the
candidates standing in a poll, and vote for them. For this dApp, we will be
accessing the deployed poll contracts using their address and ABI. This Solidity
code is what will be deployed to the blockchain, each time we create a new
election.
• MainContract is the entry point of our dApp. To create a new poll, we need to
call the createpoll() function from this deployed contract. It will maintain the total
number of election contracts deployed, their address on the network and will also
help in deploying them.
23
CHAPTER 6
First, we Initialize the working directory. Smart contracts will be made using solidity
Language and will be deployed to avalanche using truffle suite. So, we setup the
working directory according to React and Truffle. We use the web3
, which is an instance of metamask , in our App component for interacting with the
Avalanche network. Next, we need to setup our truffle project.
24
Fig. 6.1. Working directory
Solidity code will be stored in the contracts directory. Deployment functions will be
stored in the migrations folder. The truffle-config-default.js file helps us to connect
to the Avalanche network and we will require an Avalanche node’s RPC URL along
with an Avalanche wallet mnemonic for deploying the contract on the network. An
avalanche wallet is required to keep our funds, required for all the transactions on
the network. The mnemonic of the avalanche wallet is now stored in an “.env” file.
25
Fig. 6.2. Execution of React App
The app is now running successfully. We have to create an election smart contract. A
Poll.sol file is created inside of the contracts directory. This Poll smart contract is used
to view the options of the Poll, name and description of the poll, and it let us vote for
them. This solidity code will be deployed to blockchain every time we create a new
poll. We need another smart contract to maintain all the individual poll contracts
created. For this we create the MainContract.sol file inside of our contracts directory.
This will maintain the total number of poll contracts deployed, their address on the
network and will also help in deploying them. We also need to import the Poll.sol into
this file.
The smart contracts we created needs to deployed to the blockchain. We can use the
migrations directory for this. Create a file named “deploy_contracts.js” to deploy the
MainContract and Poll smart contract to blockchain. Every time we make changes to
our solidity source files or made new solidity files; we have to run “truffle compile”
26
inside the root project directory. Expected output will look like this:
Compiling your contracts...
===========================
> Compiling ./contracts/Poll.sol
> Compiling ./contracts/MainContract.sol
> Compiling ./contracts/Migrations.sol
We need funds to deploy our smart contracts to C-Chain. Inside the truffle-config.js,
HDWalletProvider will help us in deploying on Fuji C-Chain and deployment cost will
be managed by the account whose mnemonic has been stored in “the .env” file.
So, the account needs to be funded.
27
Fig. 6.3. truffle-config.js file
After funding the account, we are finally set to run migrations and deploy the
MainContract. Use the command “truffle migrate –network fuji”, followed by “truffle
migrate –network development”.
After this successful execution the migrations are created and deployed to the C-Chain.
28
Fig. 6.4 Running Migrations
29
The final step is the creation of User Interface. We require a component to connect
our browser to the avalanche network. This component is called BlockchainUtils
Component.
30
Next we need 3 main components for user interaction.
(i) CreatePoll component: This component is used to create a new poll by an user.
(ii) ActivePolls component: This component Displays the set of active polls to all
users.
(iii) VoteModal Component: This component displays the Poll information
and options available to vote. The users can cast in their vote and also provide
their opinions on the matter.
31
Fig.6.7 CreatePolls component
32
33
34
35
36
Fig. 6.8 ActivePolls Component
37
Fig. 6.9 Model summary
38
39
CHAPTER7
In this project, how Blockchain can be useful for Electronic Voting and how it
can be used for examining the confidentiality is explored. Despite the advancement
in blockchain using various techniques and networks, they still face some issues in
terms of cost and time efficiency. The proposed framework uses Avalanche network
so the gas fees and the time taken per entry is so much better than other blockchain
networks like Ethereum. In the future we can implement meta transactions to avoid
payment of gas fees on voter’s end instead we can create our own token pay with it.
Thereby this model is more secure and efficient than other electric and non-electric voting
methods.
40
APPENDIX – I
CODING
NEAR CONGIFURATION
41
helperUrl: 'https://helper.testnet.near.org',
explorerUrl: 'https://explorer.testnet.near.org',
}
case 'betanet':
return {
networkId: 'betanet',
nodeUrl: 'https://rpc.betanet.near.org',
contractName: CONTRACT_NAME,
walletUrl: 'https://wallet.betanet.near.org',
helperUrl: 'https://helper.betanet.near.org',
explorerUrl: 'https://explorer.betanet.near.org',
}
case 'local':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
keyPath: `${process.env.HOME}/.near/validator_key.json`,
walletUrl: 'http://localhost:4000/wallet',
contractName: CONTRACT_NAME,
}
case 'test':
case 'ci':
return {
networkId: 'shared-test',
42
nodeUrl: 'https://rpc.ci-testnet.near.org',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
}
case 'ci-betanet':
return {
networkId: 'shared-test-staging',
nodeUrl: 'https://rpc.ci-betanet.near.org',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
}
default:
throw Error(`Unconfigured environment '${env}'. Can be configured in
src/config.js.`)
}
}
module.exports = getConfig
Connect Wallet
<script>
const currentUrl = new URL(window.location.href);
const message = `NODE_ENV=local near create_account {newAccountId} --
masterAccount {masterAccountId} --publicKey
${currentUrl.searchParams.get('public_key')} --initialAmount
43
10000000000000000000`;
document.getElementById('shell-command').innerText = message;
function done() {
const successUrl = new URL(currentUrl.searchParams.get('success_url'));
successUrl.searchParams.set('account_id',
document.getElementById('accountId').value);
successUrl.searchParams.set('public_key',
currentUrl.searchParams.get('public_key'));
window.location.assign(successUrl.toString());
}
</script>
Utility functions
// Initializing Wallet based Account. It can work with NEAR testnet wallet that
44
// is hosted at https://wallet.testnet.near.org
window.walletConnection = new WalletConnection(near);
// Getting the Account ID. If still unauthorized, it's just empty string
window.accountId = window.walletConnection.getAccountId();
viewMethods: [
"getGreeting",
"didParticipate",
"getAllPrompts",
"getVotes",
"getUrl",
"getCandidatePair",
,
],
// Change methods can modify the state. But you don't receive the returned value
when called.
changeMethods: [
"addUrl",
"addCandidatePair",
"addToPromptArray",
"addVote",
"recordUser",
"clearPromptArray",
],
}
);
}
46
APPENDIX – II
REFERENCES
47
[8] Meter, Christian. "Design of distributed voting systems." arXiv preprint
arXiv:1702.02566 (2017).
[9] Dagher, Gaby G., Praneeth Babu Marella, Matea Milojkovic, and Jordan
Mohler. "BroncoVote: Secure Voting System Using Ethereum’s Blockchain."
(2018).
[10] Hardwick, Freya Sheer, Raja Naeem Akram, and Konstantinos
Markantonakis. "E-Voting with Blockchain: An E-Voting Protocol with
Decentralisation and Voter Privacy." arXiv preprint arXiv:1805.10258
(2018).
[11] Platform-Independent Secure Blockchain-Based Voting System by
Bin Yu, Joseph K. Liu , Amin Sakzad, Surya Nepal, Ron Steinfeld, Paul
Rimba, and Man Ho Au
[12] Adida, B.: Helios: web-based open-audit voting. In: USENIX Security
Symposium, vol. 17, pp. 335–348 (2008)
[13] Au, M.H., Chow, S.S.M., Susilo, W., Tsang, P.P.: Short linkable ring
signatures revisited. In: Atzeni, A.S., Lioy, A. (eds.) EuroPKI 2006. LNCS,
vol. 4043, pp. 101–115. Springer, Heidelberg (2006).
https://doi.org/10.1007/11774716 9
[14] Au, M.H., Liu, J.K., Susilo, W., Yuen, T.H.: Certificate based
(linkable) ring signature. In: Dawson, E., Wong, D.S. (eds.) ISPEC 2007.
LNCS, vol. 4464, pp. 79–92. Springer, Heidelberg (2007).
https://doi.org/10.1007/978-3-540-72163-5 8
[15] Yu, B., et al.: Platform-independent secure blockchain-based voting
system. Cryptology ePrint Archive, change me (2018).
http://eprint.iacr.org/2018/
48