A Blockchain based voting application using solidity, truffle and nodejs.
A democratic country is built on the foundations of elections. Election is one of the founding pillars of any democracy and hence it is imperative that this process is carried out in the most secure and transparent way. Existing voting systems are centralized in nature, are susceptibly to tampering, and have often raised suspicion among the common people.
So through this project, I aim to build a decentralized voting application where all voters will be able to register, cast their vote and personally verify these votes. In this project we have assumed that we are given with the database of voter, which have aadhaar and other credentials.
BlockVote web application uses node.js along with the express.js framework to develop the server and mongoDB as database and mongoose as object data modeling library. For the blockchain aspect, we have used the ethereum blockchain to deploy the smart contracts and web3.js library to interact with the ethereum node and the frontend. We have used Ganache and Truffle for creating a remote Blockchain environment.
The following dependencies need to be installed.
- node.js
- npm
- mongodb / mongodb atlas
- web3.js
- Ganache
- Truffle
Retrieve the project (clone the repository using the command)
git clone https://github.com/Anish-U/BlockVote.git
After cloning the repository, navigate into the directory and run the following command to install all the dependencies
npm install
Setup the environment variables by creating .env file in root directory
PORT = 3000
DB_URI = "mongodb://localhost:27017/BlockVote"
GANACHE_URI = "http://localhost:7545"
SESSION_SECRET = "SESSION_SECRET_KEY_HERE"
JWT_KEY = "JWT_SECRET_KEY_HERE"
Add few voters and one admin into database as we assume that the application is already given with the voter details.
// MongoDB CLI
db.voters.insertOne(
{
aadhaar: "234567892345",
name: "Ummenthala Anish",
password:"$2a$12$s1Ue2JOpIq2Vk/H3HjDFgeNtvxRM4tGBCyZr6Nw4SOIf/75LISEm2",
gender:"male"
}
)
db.admins.insertOne(
{
username: "admin",
password:"$2a$12$s1Ue2JOpIq2Vk/H3HjDFgeNtvxRM4tGBCyZr6Nw4SOIf/75LISEm2",
}
)
Note: Password hash can be generated at Bcrypt
Run ganache application in the background
Open the terminal and compile the Smart Contract to create the ABI of the smart contract and network id.
After compiling we need to migrate the contracts.
truffle compile
truffle migrate --reset
In another terminal, run the command
npm run devStart (or) node server.js
When the command runs successfully. Go to localhost:3000 there you will land on the home page of the project.
- MongoDB - Database
- Express - Server Framework
- NodeJs - Server Environment
- Solidity - Used to develop Smart contracts
- Truffle - Development environment, testing framework for blockchains
- Ganache - Personal blockchain for rapid Ethereum distributed application development
- Web3JS - Library that allow you to interact with a local or remote ethereum node.