A secure, transparent, and tamper-proof voting system built on the Ethereum blockchain. This project enables creation of elections, adding candidates, and casting votes in a fully decentralized manner.
- Decentralized: No central authority controls the voting process
- Transparent: All votes are recorded on the blockchain and can be verified
- Tamper-proof: Once a vote is cast, it cannot be changed or deleted
- One person, one vote: Smart contract ensures each address can only vote once per election
- Time-based elections: Elections have defined start and end times
- Real-time results: Vote counts are updated in real-time on the blockchain
- Admin controls: Admin can activate/deactivate elections if needed
- Node.js >= 16.x
- npm or yarn
- MetaMask or any Web3 wallet
- Git
git clone <repository-url>
cd evotingnpm installnpm run compilenpm run testnpm run nodeIn a new terminal, deploy the contract to the local network:
npm run deploy:localhostYou can use any static file server to serve the frontend. For example:
npx http-server ./frontend -p 3000Then open http://localhost:3000 in your browser.
evoting/
βββ contracts/
β βββ Voting.sol # Main smart contract
βββ scripts/
β βββ deploy.js # Deployment script
βββ test/
β βββ Voting.test.js # Contract tests
βββ frontend/
β βββ index.html # Frontend HTML
β βββ app.js # Frontend JavaScript
βββ deployments/ # Deployment info (created after deploy)
βββ hardhat.config.js # Hardhat configuration
βββ package.json # Project dependencies
βββ README.md # This file
| Function | Description |
|---|---|
admin() |
Returns the admin address |
electionCount() |
Returns total number of elections |
totalVotesCast() |
Returns total votes across all elections |
getElection(id) |
Returns election details |
getCandidate(electionId, candidateId) |
Returns candidate details |
getAllCandidates(electionId) |
Returns all candidates for an election |
getWinner(electionId) |
Returns the winner of an ended election |
checkVoterStatus(electionId, voter) |
Checks if an address has voted |
| Function | Description |
|---|---|
createElection(name, description, startTime, endTime) |
Creates a new election |
addCandidate(electionId, name, description) |
Adds a candidate to an election |
castVote(electionId, candidateId) |
Casts a vote |
deactivateElection(electionId) |
Deactivates an election (admin only) |
activateElection(electionId) |
Reactivates an election (admin only) |
- Create a
.envfile in the project root:
PRIVATE_KEY=your_wallet_private_key
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/your_infura_key
GOERLI_RPC_URL=https://goerli.infura.io/v3/your_infura_key
ETHERSCAN_API_KEY=your_etherscan_api_key- Get testnet ETH from faucets:
- Sepolia: https://sepoliafaucet.com/
- Goerli: https://goerlifaucet.com/
npm run deploy:sepolianpm run deploy:goerliThe project includes comprehensive tests covering:
- Election creation
- Candidate management
- Voting mechanics
- Double voting prevention
- Time-based restrictions
- Admin functions
- View functions
Run tests with:
npm run testRun tests with gas reporting:
REPORT_GAS=true npm run testThe contract emits the following events that can be listened to:
ElectionCreated: When a new election is createdCandidateAdded: When a candidate is added to an electionVoteCast: When a vote is castElectionActivated: When an election is activatedElectionDeactivated: When an election is deactivated
- One vote per address: The contract prevents double voting by tracking which addresses have voted
- Time restrictions: Voting is only allowed during the defined election period
- Admin controls: Only the admin can activate/deactivate elections
- Creator permissions: Only the election creator or admin can add candidates
- Input validation: All inputs are validated before processing
- Modern, responsive UI with glassmorphism design
- MetaMask wallet integration
- Real-time election status updates
- Easy-to-use voting interface
- Election creation with multiple candidates
- Vote status tracking
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or need help, please open an issue in the repository.
- Add voter registration/whitelist functionality
- Implement weighted voting
- Add support for multiple voting methods (ranked choice, approval voting)
- Create a mobile app
- Add multi-chain support
- Implement vote delegation
Built with β€οΈ using Solidity, Hardhat, and Ethers.js