Your blockchain-powered voting platform is now complete with full integration between frontend, backend, and blockchain!
- Frontend (Next.js) - Port 3000
- Backend (Express + TypeScript) - Port 5000
- Database (MongoDB Atlas)
- Blockchain (Hardhat Local Network) - Port 8545
- Unique ID:
ADMIN-AGR-001 - Phone:
8888888001 - MPIN:
1234 - Role: Admin (can verify users)
- Unique ID:
EC-AGR-001 - Phone:
7777777001 - MPIN:
1234 - Role: Election Commission (can create elections)
cd blockchain
npx hardhat nodeKeep this terminal running. It provides the local Ethereum network.
cd server
npm run devBackend runs on http://localhost:5000
cd client
npm run devFrontend runs on http://localhost:3000
- Go to http://localhost:3000/auth
- Enter Unique ID:
ADMIN-AGR-001 - Click "Request OTP"
- Check backend console for OTP (6-digit code)
- Enter OTP and MPIN:
1234 - ✅ Logged in as Admin
- Click "Register" tab on auth page
- Fill registration form with:
- Full name
- Phone (10 digits)
- Aadhaar (12 digits)
- Address
- Age
- Voter ID
- Upload Aadhaar Card PDF
- Upload Voter ID Card PDF
- Submit registration
- ✅ Registration pending admin approval
- Login as Admin
- Go to Admin Dashboard → Pending Users
- Review user documents
- Click "Verify User"
- Set initial MPIN for user (4 digits)
- ✅ User verified, SBT token issued on blockchain
- User receives unique ID (format:
AGR-XXXXXXX)
- Login as EC (
EC-AGR-001) - Go to EC Dashboard → Create Election
- Fill election details:
- Title
- Description
- Start Date
- End Date
- Parties (name, symbol, manifesto)
- Click "Create Election"
- ✅ Election created in MongoDB AND blockchain
- User logs in with their unique ID
- See active elections
- Select an election
- Review party manifestos
- Cast vote for preferred party
- ✅ Vote recorded in MongoDB AND blockchain (immutable)
When: Admin verifies a user What Happens:
- User gets blockchain wallet address
- Non-transferable SBT (Soulbound Token) issued
- Token stored in User document
- Contract:
0x5FbDB2315678afecb367f032d93F642f64180aa3
When: EC creates election What Happens:
- Election details stored on blockchain
- Transaction hash saved in MongoDB
- Immutable record of election parameters
- Contract:
0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
When: User votes in election What Happens:
- Vote recorded in MongoDB (fast query)
- Vote recorded on blockchain (immutable proof)
- Double-vote prevention at both layers
- Transaction hash stored with vote
// In Node.js console or browser console
const deployments = require('./blockchain/deployments/localhost.json')
console.log('SBT Contract:', deployments.contracts.SBT)
console.log('Voting Contract:', deployments.contracts.VotingContract)// Using ethers.js
const { ethers } = require('ethers')
const provider = new ethers.JsonRpcProvider('http://127.0.0.1:8545')
const votingContract = new ethers.Contract(
'0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
VotingABI,
provider
)
// Check total votes
const totalVotes = await votingContract.getTotalVotes(electionId)
console.log('Total votes on blockchain:', totalVotes.toString()){
"uniqueId": "AGR-XXXX",
"fullName": "string",
"phone": "string",
"aadhaar": "string",
"role": "user|admin|election_commission|voter",
"mpin": "hashed",
"walletAddress": "0x...",
"sbtTokenId": "string",
"isVerified": true
}{
"title": "string",
"description": "string",
"startDate": "Date",
"endDate": "Date",
"status": "draft|active|ended",
"parties": [...],
"blockchainTxHash": "0x..."
}{
"electionId": "ObjectId",
"userId": "uniqueId",
"partyId": "string",
"votedAt": "Date",
"blockchainTxHash": "0x..."
}✅ Role-based authentication (Admin, EC, Voter) ✅ OTP-based login with MPIN ✅ Document upload for user verification ✅ Blockchain wallet generation per user ✅ Soulbound Token (SBT) for identity ✅ Election creation with blockchain storage ✅ Vote casting with blockchain immutability ✅ Double-vote prevention (DB + Blockchain) ✅ Real-time vote counting ✅ Audit trail via blockchain ✅ Responsive UI with animations
PORT=5000
MONGODB_URI=mongodb+srv://...
JWT_SECRET=your-secret
BLOCKCHAIN_RPC_URL=http://127.0.0.1:8545
SBT_CONTRACT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
VOTING_CONTRACT_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
ADMIN_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80NEXT_PUBLIC_API_URL=http://localhost:5000/api
NEXT_PUBLIC_DEV_MODE=true
NEXT_PUBLIC_DEV_KEY=agora_dev_2024- Problem: Contract not initialized
- Solution: Ensure Hardhat node is running and contracts are deployed
- Problem: API calls failing
- Solution: Check NEXT_PUBLIC_API_URL points to correct backend
- Problem: Transactions failing
- Solution: Restart Hardhat node and redeploy contracts
- Email/SMS Services: Real OTP delivery (currently console)
- Results Visualization: Charts and graphs for election results
- Vote Verification: Let users verify their vote on blockchain
- Multiple Elections: Support concurrent elections
- Proposal System: Implement proposal voting
- Deploy to Testnet: Move from local to Sepolia/Mumbai
- Mobile App: React Native version
- Advanced Security: Encryption, rate limiting, etc.
- Show Admin Flow: Register → Verify → Show SBT on blockchain
- Show EC Flow: Create election → Show on blockchain
- Show Voter Flow: Login → Vote → Show vote on blockchain
- Show Immutability: Try to vote twice (prevented)
- Show Transparency: Query blockchain for vote counts
If you encounter any issues:
- Check all three services are running (Frontend, Backend, Blockchain)
- Verify environment variables are correct
- Check console logs for errors
- Ensure MongoDB connection is active