Voting using Blockchain

Vishwas
5 min readOct 6, 2020

Smart Contracts | IPFS | Online Voting | React | Web3 | Semantic-UI

Voting Using Blockchain…….never heard of it? In this post, I have described how I implemented it and how it can be used.

It’s sooooooooooooooooooooo easy.

Introduction

Voting via the ballot box or electrical machine is dangerous. As votes can be altered and there’s no proof or track whether your vote is considered or not. And if some person wants to alter votes they have to attack a single site which raises questions on security and increases risk.

Why blockchain?
Using Blockchain, we can overcome all this.

Blockchain is a publicly available distributed ledger. Voters send their votes as a transaction to the Ethereum network, all the votes are encrypted. Since it is public, voters can check the status of their votes. Also, blockchain is immutable, once some data is added to it, it can’t be altered or deleted. Immutability is what we need while voting, voters votes shouldn’t be altered.

Smart Contracts are used which are coded and will work, no one can stop them. Using them, voting can be done on time and results would be declared instantly. Contracts are publicly available, so anyone can read them. Due to which, it brings trust to the system.

Proposed System

Voting has 3 stages/states: Campaigning, Voting, and Results.

Campaigning: Candidates can register themselves with their unique id.
Voting: Voters vote using their unique id.
Results: The candidate having the maximum votes will be declared as the winner.

After results are declared, a contract will be deployed — Bill having with some tokens and the winning party as owner of the contract. The party can propose bills if the bill gets more than 50% votes, then it is passed or else rejected. This gives power to people.

Rather than giving tokens to the party, we would give it to the contract and for transactions, the party has to use this contract only. As all the transactions are done by contract, it is easy to see where money has been used. Citizens/Voters can see and verify all the transactions. Hence, using the contract we can bring trust and transparency.

Technologies Used

UI

I have used React and next.js (which is a react framework) for rendering components. Using react, there was minimum code-reusability.
Also used, semantic-UI for react which had already pre-made up tags.

Smart Contracts

Two smart contracts — Voting and Bills. Smart contracts are written in language — solidity. Writing contracts is like business logic or contract. A smart contract once it is written & deployed, can’t be changed, it will execute no matter what. Due to this both the parties are satisfied and ensured that their deal is secure and trustable.

Web3.js

For interaction between interface and contract, I have used web3.js. It has the function needed to deploy a contract and call its method.

IPFS

IPFS is a file-sharing system that can be used to store files. IPFS uses cryptography hashes that can be stored on the blockchain. Using IPFS, I will store parties' symbols. Also, using this we can store the user’s face too or some important document.

Work Done

This is the home page, where all candidate's list will be available. The voter just has to click on the candidate button and his/her vote would be submitted.
Note: Voter can only vote if the state is “Voting”. The state is shown on the right side of the header.

Home Page

Candidates' details will be added to the form so that they can take part in the election. Same for voters. Once the voters are registered, they can vote only once. The logo, of a party, is stored on the IPFS network.
Note: These details are entered only when the state — campaigning and only the owner can add details.

Owner can add candidates and voters.

After a voter has voted, a receipt is generated with having their address and transaction hash. They can verify their transaction on etherscan. This receipt is proof that they have voted.
Note: I have used the etherscan-Rinkbey test network, for testing purposes. For real-life projects, etherscan-Main Network should be used.

Voting Receipt

After voting is done, the owner of the contract declares the results. A new contract — Bills is deployed at the given address. And the winning party is the owner of this contract.

Results of election

After results are declared, Bills contract is deployed where the winning party can propose bills. This bill should be approved by at least 50% of voters or citizens.

Propose a bill

After a bill is proposed, anyone can Up-Vote or Down-Vote for a particular bill. Voters can read the proposal and take the decision.

Requested Bill Voting

We have sent tokens to the Bills contract, so if the winning party wants to make a transaction they have to use the below form. After a successful transaction, the transaction list is updated and anyone can verify it.

Transactions done by the winning party

As said earlier, Blockchain is a publicly distributed ledger so anyone can see the transactions.
Below are all the transactions done from the contract- Bills. Thus, transparency.

Etherscan Rinkbey Test Network

Problems

· Someone has to deploy the contract and start the election.

· The owner of the contract has to add candidates and voters. Thus, making the system dependent on the owner.

· Transaction done for any military purpose should be kept secret.

· No way of verifying who has voted? There should be some way like a fingerprint or face detection.

· Candidates should be verified.

Github

So here is my project Github link.
Open to suggestions.

--

--

Vishwas

bio= “I’m a java developer & also exploring blockchain. Hope my projects r beneficial for u. Follow for more.” ; cout<<bio; //btw did u find any errors here ^_^