E-Voting System Based on Blockchain

Sheefa Jalali
Coinmonks
4 min readJun 7, 2023

--

Here is an explanation of how to implement an E-Voting System using Blockchain technology.

This project was designed and developed by me for my final year.

You can get the source code at https://github.com/shifaj22/E-Voting_System_Blockchain

Blockchain is a technology rapidly gaining momentum in the era of Industry 4.0. With high security and transparency provisions, it is being widely used in supply chain management systems, healthcare, payments, business, IoT, voting systems, etc.

Why do we need this?

Current voting systems like ballot box voting or electronic voting suffer from various security threats such as DDoS attacks, polling booth capturing, vote alteration and manipulation, malware attacks, etc, and require vast amounts of paperwork, human resources, and time. This creates a sense of distrust among existing systems. Using blockchain, the voting process can be made more secure, transparent, immutable, and reliable.

Programming Languages used:

For Smart Contract: Solidity

Solidity is an object-oriented programming language created specifically by the Ethereum Network team for constructing and designing smart contracts on Blockchain platforms.

Frontend: JavaScript, HTML, CSS

Development Tools:

Truffle:

Truffle is a world-class development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier. Truffle is widely considered the most popular tool for blockchain application development.

Ganache:

Ganache is a software tool that developers widely use to create a local blockchain network for testing and development purposes. Developers may effectively test different scenarios and troubleshoot their blockchain apps by simulating a blockchain network on their local PC with Ganache.

First, you need to download and install these:

Node.js / npm

https://nodejs.org/en/download

Truffle

https://trufflesuite.com/docs/truffle/how-to/install/

Ganache

https://trufflesuite.com/ganache/

Also, do not forget to add MetaMask Extension to your browser.

https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn

Install these additional packages just in case to avoid errors:

Web3.js: npm i web3

Solidity (solc-js): npm i solc

Steps to implement the project:

Step 1:

Clone the GitHub repository “git clone https://github.com/shifaj22/E-Voting_System_Blockchain

Step 2:

Connecting MetaMask and Ganache

  • In MetaMask, go to settings > networks > add network. You can also get to this by clicking the MetaMask extension pinned on your browser > clicking the profile picture > settings > networks > add network.
  • Name the network Ganache.
  • For the New RPC URL go to ganache where you’ll copy the RPC server URL and paste it into Metamask.
  • The chain ID for the ganache is 1337.
  • You can name the currency symbol “ETH” and save.

Step 3:

Check the truffle-config.js file. The port number should be set to 7545 as we are not using the ganache-cli.

Step 4:

cd E-Voting_System_Blockchain

npm i

truffle migrate — reset

(You should see the contract being deployed. To confirm whether the contract has been deployed or not, open Ganache and check if Ethereum is deducted from the first account, it should be 99.99 ETH)

npm start

Step 5:

Importing an account from Ganache to MetaMask.

  • Open ganache and click on the key icon of the first account. The show keys button is the key icon.
  • Copy the private key and click done.

[NOTE: The first account in ganache is used for admin login. Make sure to import the private key of the first account into MetaMask to access the Admin Panel]

  • Open the MetaMask menu which can be accessed by clicking the profile picture and selecting import account.
  • Paste the private key copied from ganache and click import.

After the project successfully runs on localhost:3000, register yourself as the admin, you can also access the Admin Panel and add candidates. After adding the candidates click on the “Start Election” button.

If you want to add different users/voters then, import the private keys of different accounts from Ganache to MetaMask and connect those accounts to the current site and register as a different user/voter to cast a vote.

--

--