Ethereum based voting system
An ethereum based secure voting system
Created on 8th February 2026
•
Ethereum based voting system
An ethereum based secure voting system
The problem Ethereum based voting system solves
🗳️ The Problem It Solves
Traditional voting systems — whether physical or digital — suffer from serious challenges:
❌ Lack of transparency
❌ Risk of vote tampering
❌ Duplicate or fake voting
❌ Manual result manipulation
❌ Low trust in centralized authorities
❌ Complex voter verification processes
Even many online voting platforms are centralized, meaning:
One authority controls the database
Votes can be altered internally
Users cannot independently verify results
This creates trust issues, security risks, and reduced participation.
🚀 What This Project Solves
This blockchain-based voting system provides:
🔐 1. Tamper-Proof Voting
Votes are recorded on the blockchain, making them:
Immutable
Transparent
Publicly verifiable
Impossible to modify after submission
Once a vote is cast, it cannot be changed or deleted.
🛡️ 2. Secure Identity Verification
Using OTP-based verification + wallet authentication:
Prevents duplicate voting
Links one vote to one wallet
Ensures only verified users participate
This makes the system secure without exposing sensitive identity data on-chain.
🧾 3. Fully Transparent Results
Anyone can:
View live vote counts
Verify results directly from blockchain data
Audit the entire election process
No hidden counting. No manual manipulation.
⚡ 4. Faster & Automated Elections
No manual vote counting
No result compilation delays
No human calculation errors
Results are available instantly after voting ends.
🏛️ 5. Useful For
This system can be used for:
🏫 College/University elections
🏢 Corporate board voting
🗳️ DAO governance voting
🏘️ Housing society decisions
🧑💻 Hackathons & community polls
🌍 Remote / digital elections
💡 How It Makes Things Easier
Instead of:
Manual ballots → Counting errors → Result disputes
You get:
Verified wallet → Secure vote → Automatic blockchain result → Transparent audit
No paperwork.
No manipulation.
No middlemen.
🌍 Bigger Impact
This project demonstrates how blockchain can:
Increase trust in digital democracy
Reduce election fraud
Enable remote secure participation
Provide public auditability
It brings trustless voting to small organizations today — and scalable digital governance tomorrow.
Challenges we ran into
⚙️ Challenges I Ran Into
Building a full-stack blockchain voting system (React + Node + Smart Contracts + MetaMask) was not smooth 😅
Here are the biggest hurdles I faced and how I solved them.
1️⃣ “Voter not registered” Revert Error
🔥 The Problem
When trying to vote, the transaction kept reverting with:
execution reverted: "Voter not registered"
Even though:
Wallet was connected
OTP verification was successful
The UI looked correct
🧠 Why It Happened
The smart contract required voters to be registered before the election started:
modifier electionNotStarted(uint256 _electionId) {
require(block.timestamp < elections[_electionId].startTime, "Election already started");
_;
}
But I was trying to:
Register voter after election start
Or auto-register during voting
So registration was silently failing, and voting reverted.
✅ How I Solved It
Carefully reviewed contract modifiers
Added proper registration flow before election start
Added better frontend error handling using err.reason
Logged signer address and electionId to verify correctness
This taught me how strict blockchain state logic can be.
2️⃣ MetaMask Not Connecting
🔥 The Problem
I kept getting:
MetaMask extension not found
Failed to connect to MetaMask
Even though MetaMask was installed.
🧠 Why It Happened
I mistakenly checked:
window.Etherium
Instead of:
window.ethereum
Also sometimes:
MetaMask was disabled for localhost
Wrong network selected
✅ Fix
Corrected provider detection
Ensured MetaMask allowed on the site
Forced network switch to Sepolia
Restarted browser session
Lesson learned: case sensitivity matters 😅
3️⃣ Invalid Contract Target Error
🔥 The Problem
invalid value for Contract target
value=null
or sometimes a huge number instead of an address.
🧠 Why It Happened
The contract address was:
Not set in .env
Parsed incorrectly
Not passed properly to ethers.Contract
✅ Fix
Properly configured VITE_CONTRACT_ADDRESS
Restarted dev server after env changes
Added safety checks in getContract()
Logged contract address before instantiation
This reinforced how environment variables behave in Vite.
4️⃣ Backend Route 404 Errors
🔥 The Problem
Cannot POST /api/election/register-voter
Even though I thought the route existed.
🧠 Why It Happened
Route was not mounted correctly
Path mismatch (/api/election/... vs /election/...)
Server not restarted
✅ Fix
Verified Express route structure
Checked app.use("/api/election", router)
Confirmed backend was running on correct port
5️⃣ Hook Errors in React
🔥 The Problem
Rendered more hooks than during previous render
Invalid hook call
🧠 Why It Happened
I accidentally:
Used hooks inside loops
Placed useNavigate() inside a condition
Called hooks inside map()
✅ Fix
Moved all hooks to the top of the component, respecting React rules:
Hooks must always be called unconditionally and at the top level.
6️⃣ Smart Contract Design Mistake
At one point:
elections[electionId].candidates[candidateId].voteCount++;
But candidates was actually a separate mapping:
mapping(uint256 => mapping(uint256 => Candidate)) public candidates;
This mismatch caused logical inconsistencies.
✅ Fix
Refactored vote function to:
candidates[electionId][candidateId].voteCount++;
This made the storage structure consistent.
🧠 What I Learned
Blockchain errors are deterministic — read revert reasons carefully.
Frontend must respect contract rules strictly.
Registration logic and election timing are critical.
Environment configuration is fragile but important.
Debugging Web3 requires checking:
Network
Contract address
Signer
Parameters
Contract modifiers
🚀 Biggest Takeaway
This project taught me that:
Web3 development is not just coding — it’s syncing frontend logic, backend APIs, blockchain state, and wallet behavior perfectly.
Even small mismatches cause complete failure.
But once everything aligns — it works beautifully.
Tracks Applied (1)
Ethereum Track
ETHIndia
