Skip to content

Decentralized voting system using Ethereum smart contracts, React, and Node.js for secure, transparent elections.

Notifications You must be signed in to change notification settings

abdulbaqi02/Blockchain-Based-Voting-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

4 5 1 HomePage# Blockchain-Based-Voting-System

Block Vote — Decentralized Voting System

A secure, transparent voting web application that integrates a React frontend, Node/Express backend, and Ethereum smart contracts. This README explains how to set up, run, test, and deploy the project.

Repository links

Contents

  • Overview
  • Prerequisites
  • Setup (install & env)
  • Local development (server + client)
  • Smart contracts (Ganache, Truffle, deployment)
  • MetaMask configuration
  • Building & Production
  • Deployment options & links
  • Troubleshooting

Overview

  • Frontend: React + Chakra UI (client)
  • Backend: Node.js + Express + SQLite (or production PostgreSQL) (server/index.js)
  • Smart contracts: Truffle-based contracts in contracts
  • Authentication: JWT, bcrypt
  • OTP email verification via Gmail (nodemailer)

Prerequisites

  • Node.js v14+ (recommend v16 or v18)
  • npm (or yarn)
  • Truffle (for contract deployment): npm install -g truffle
  • Ganache CLI or Ganache GUI (for local blockchain): see server/ganache-setup.md
  • MetaMask browser extension

Quick setup (local)

  1. Clone the repo and open it: git clone cd block-vote

  2. Install dependencies

    • Install root dependencies and client/server: npm run install-all
    • Or manually: npm install cd client && npm install cd ../server && npm install
  3. Environment variables

    • Create a .env in server/ (see below). Example: PORT=5000 NODE_ENV=development EMAIL_USER=your-gmail@gmail.com EMAIL_PASS=your-app-specific-password JWT_SECRET=your-secret-key-min-32-chars ETHEREUM_NODE_URL=http://127.0.0.1:7545 CONTRACT_ADDRESS=<deployed_contract_address> ADMIN_ETHEREUM_ADDRESS=<ganache_admin_address> CHAIN_ID=1337
    • Frontend environment (for local dev you can use client/.env): REACT_APP_API_URL=http://localhost:5000 REACT_APP_NETWORK_ID=1337 REACT_APP_NETWORK_NAME=Local Ganache REACT_APP_RPC_URL=http://127.0.0.1:7545

    Files referenced in this repo:

Local development (run app)

  1. Start Ganache (see below) or ensure ETHEREUM_NODE_URL points to your node.

  2. Start both server and client concurrently (recommended): npm run dev

    • This runs the server (nodemon) and client (React dev server). See scripts.dev.
  3. Alternatively run individually:

    start server

    cd server npm start

    in another terminal start client

    cd client npm start

  4. Open browser:

Smart contracts (Ganache & Truffle)

  • Quick Ganache setup:

    • CLI: ganache-cli -p 7545 -i 1337 --accounts 10 --defaultBalanceEther 100
    • Or use Ganache GUI and set RPC server to http://127.0.0.1:7545, Network ID 1337.
    • See full instructions and verification commands in server/ganache-setup.md.
  • Deploy contracts locally: cd contracts truffle migrate --reset --network development

    • The Truffle network config lives in contracts/truffle-config.js.
    • After deployment, copy the deployed contract address into server/.env as CONTRACT_ADDRESS. Also update ADMIN_ETHEREUM_ADDRESS.
  • Artifacts:

MetaMask setup

  1. Install MetaMask browser extension.
  2. Create or import an account.
  3. Add a custom RPC network for Ganache:
  4. Import an account private key from Ganache (the private key printed by Ganache) into MetaMask for testing.
  5. Ensure the wallet address matches ADMIN_ETHEREUM_ADDRESS in server/.env where needed.

Building for production

  1. Build frontend: cd client npm run build

    • The built files will be in client/build/.
  2. Serve static frontend from server:

  3. Run server (production): NODE_ENV=production PORT=8080 node server/index.js

    • Or use process managers (pm2) or containerize (see below).

Deployment options

  • Short list (full steps in DEPLOYMENT_GUIDE.md):
    • Frontend: Vercel or Netlify (deploy client/)
    • Backend: Railway, Render, or Heroku (set root to server/ for Railway)
    • All-in-one: Railway using a monorepo Dockerfile (see DEPLOYMENT_GUIDE.md)
    • Database: SQLite is included. For production use PostgreSQL — the guide gives sample server/config/database.js adjustment.

Sample .env (server/.env.production) PORT=8080 NODE_ENV=production DATABASE_URL=postgres://username:password@host:5432/database EMAIL_USER=your-gmail@gmail.com EMAIL_PASS=your-app-specific-password JWT_SECRET=your-super-secret-jwt-key-min-32-chars CORS_ORIGIN=https://your-frontend-url.vercel.app

Useful scripts (from package.json)

  • npm start — run server (node server/index.js)
  • npm run client — start frontend dev server
  • npm run server — start backend with nodemon
  • npm run dev — run client & server concurrently
  • npm run install-all — install root, client, and server deps
  • npm run build — builds frontend: cd client && npm run build

Troubleshooting & tips

  • CORS errors: confirm CORS_ORIGIN in server env.
  • DB connection: ensure DATABASE_URL is valid for PostgreSQL; SQLite file included for local testing.
  • MetaMask network mismatch: set chain id / RPC as in Ganache or testnet RPC.
  • Email (OTP) not sending: verify Gmail app password and EMAIL_USER/EMAIL_PASS.
  • Contract issues: re-run truffle migrate --reset and update contract address in server/.env.

Where to read more in this repo

4 5 6 Manage Election 4 5 5  Creating Election Page 4 5 4 Admin Adding Contestant for ELection 4 5 2 admin login 4 5 1 HomePage Voter Management User site Results 4 5 13 Results After Casted Vote (live Vote Count) 4 5 12 user Voting Area 4 5 11 user's voter registration 4 5 10 User info 4 5 9 user login 4 5 8 user create account 4 5 7 Admin site result section 4 5 6 2 Election Started 4 5 6 1 Admin to select time duration for Election

About

Decentralized voting system using Ethereum smart contracts, React, and Node.js for secure, transparent elections.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published