You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A full-stack blockchain-based voting platform built on Polygon Amoy with an Express.js backend, MongoDB Atlas database, and Cloudinary image storage. Designed to be transparent, tamper-proof, and deployable at zero cost.
git clone https://github.com/trynafind-sumanyu/decentralised-voting-system.git
cd decentralised-voting-system
2. Install backend dependencies
cd backend
npm install
3. Install blockchain dependencies
cd ../blockchain
npm install
4. Configure environment variables (see below)
5. Start the backend
cd backend
npm run dev
# Server running on port 5000# MongoDB connected successfully
6. Open the frontend
open frontend/index.html
⚙️ Environment Variables
backend/.env
PORT=5000NODE_ENV=development# MongoDB AtlasMONGO_URI=mongodb+srv://<user>:<pass>@cluster.mongodb.net/voting# Admin credentials (you choose these)ADMIN_USERNAME=adminADMIN_PASSWORD=YourStrongPassword123ADMIN_TOKEN_SECRET=some-long-random-secret-string# BlockchainPRIVATE_KEY=0xyour_wallet_private_keyNETWORK=amoyRPC_URL_AMOY=https://polygon-amoy.g.alchemy.com/v2/YOUR_KEYRPC_URL_LOCAL=http://127.0.0.1:8545AMOY_CONTRACT_ADDRESS=0xYourDeployedContractAddress# Cloudinary (from cloudinary.com dashboard)CLOUDINARY_CLOUD_NAME=your_cloud_nameCLOUDINARY_API_KEY=your_api_keyCLOUDINARY_API_SECRET=your_api_secret# CORS - set to your Vercel URL in productionALLOWED_ORIGIN=https://your-app.vercel.app
cd blockchain
npx hardhat run scripts/deploy.js --network amoy
# Contract deployed to: 0xABC123... <- copy this address
Step 2 — Deploy Backend to Render
Go to render.com → New Web Service → connect GitHub repo
Set Root Directory to backend
Set Build Command to npm install
Set Start Command to npm start
Add all env vars from backend/.env above
Click Deploy
Step 3 — Deploy Frontend to Vercel
Go to vercel.com → New Project → import GitHub repo
Set Root Directory to frontend
Leave build command blank (static site)
Click Deploy
Step 4 — Update CORS
In Render → Environment → set:
ALLOWED_ORIGIN=https://your-app.vercel.app
Then redeploy backend.
📚 API Reference
Base URL:https://voting-system-backend-9xsy.onrender.com/api
Voters
Method
Endpoint
Description
POST
/voters
Register a new voter
GET
/voters/lookup?aadharNumber=
Sign in / look up voter
Elections
Method
Endpoint
Auth
Description
GET
/elections
—
List all elections
POST
/elections
Admin
Create election
GET
/elections/:id/results
—
Get vote results
Candidates
Method
Endpoint
Auth
Description
GET
/candidates?electionId=
—
List approved candidates
POST
/candidates
—
Register candidate (with photo)
GET
/candidates/admin?electionId=
Admin
List all candidates
PATCH
/candidates/:id/approval
Admin
Approve or reject candidate
Votes
Method
Endpoint
Description
POST
/votes
Cast a vote
Admin
Method
Endpoint
Description
POST
/admin/login
Admin login → returns JWT
GET
/admin/session
Verify admin session
⛓️ Smart Contract
File:blockchain/contracts/Voting.sol
function addCandidate(stringmemory_name) publicfunction vote(stringmemory_voterId, uint_candidateId) publicfunction getAllCandidates() publicviewreturns (Candidate[] memory)
Votes are tracked by _voterId (a scoped string combining MongoDB voter + election IDs) instead of msg.sender — this allows multiple voters to use the same backend wallet without triggering the already-voted check.