An educational decentralized voting prototype built with Solidity, Hardhat, Ethereum-compatible blockchain technology, and Ethers.js.
The project demonstrates how blockchain technology can be used to implement a transparent and auditable voting system with voter registration, candidate management, election-state control, and one-vote-per-wallet enforcement.
Educational Purpose: This project is a prototype intended for learning, academic demonstration, and experimentation. It is not designed for real-world elections.
- Voter Registration — Maintains a blockchain-based registry of eligible voters.
- Candidate Management — Allows authorized management of election candidates.
- One Vote Per Wallet — Prevents a registered wallet from voting more than once.
- Election State Management — Controls the lifecycle of an election.
- Transparent Vote Counting — Votes and election state are stored on-chain.
- Result Calculation — Provides a mechanism for determining election results.
- Access Control — Restricts administrative operations to authorized accounts.
- Auditable State — Blockchain transactions provide a transparent record of contract activity.
- Hardhat Testing — Includes automated tests for core contract functionality.
- Remix Compatibility — The contract can be deployed and tested using Remix for demonstration purposes.
| Technology | Purpose |
|---|---|
| Solidity | Smart contract development |
| Hardhat | Development, compilation, and testing |
| Ethers.js | Ethereum blockchain interaction |
| JavaScript | Deployment scripts and tests |
| Ethereum / EVM | Smart contract execution environment |
| Remix IDE | Optional browser-based deployment and simulation |
| Git & GitHub | Version control and project hosting |
Blockchain-Based-Voting-System/
│
├── contracts/
│ └── VotingSystem.sol
│
├── scripts/
│ └── deploy.js
│
├── test/
│ └── VotingSystem.test.js
│
├── docs/
│ └── ...
│
├── hardhat.config.js
├── package.json
├── package-lock.json
├── .gitignore
└── README.md
The voting process follows a controlled election lifecycle:
Administrator
│
├── Register Eligible Voters
│
├── Register Candidates
│
├── Start Election
│
▼
Eligible Voters
│
├── Connect Wallet
│
├── Select Candidate
│
└── Cast Vote
│
▼
Blockchain
│
├── Verify voter eligibility
├── Verify voter has not voted
├── Record vote
└── Update candidate vote count
│
▼
Election Ends
│
▼
Calculate / Display Results
The VotingSystem.sol contract is responsible for maintaining the election state and enforcing the voting rules.
Typical responsibilities include:
The contract maintains information about eligible voters and ensures that only registered voters can participate.
Candidates can be registered before the election begins according to the access-control rules implemented in the contract.
When a voter casts a vote, the contract verifies:
- The voter is eligible.
- The election is currently active.
- The voter has not already voted.
- The selected candidate is valid.
After successful validation, the vote is permanently recorded on the blockchain.
The election follows defined states such as:
Not Started
↓
Active
↓
Ended
Administrative actions can be restricted based on the current state.
Make sure you have Node.js and npm installed.
Clone the repository:
git clone https://github.com/rohitsingh83/Blockchain-Based-Voting-System.git
cd Blockchain-Based-Voting-SystemInstall dependencies:
npm installRun:
npx hardhat compileA successful compilation should generate the required Hardhat artifacts.
Execute the automated test suite:
npx hardhat testThe tests are intended to verify important election and voting rules, including voter eligibility, candidate registration, election state transitions, and prevention of multiple votes from the same wallet.
Start a local Hardhat blockchain:
npx hardhat nodeIn a second terminal, deploy the contract:
npx hardhat run scripts/deploy.js --network localhostThe deployment script will deploy the VotingSystem contract to the local development blockchain.
The smart contract can also be tested through Remix IDE.
General workflow:
- Open Remix IDE.
- Upload
contracts/VotingSystem.sol. - Select an appropriate Solidity compiler version.
- Compile the contract.
- Select Remix VM or an injected wallet environment.
- Deploy the contract.
- Register candidates and eligible voters.
- Start the election.
- Cast votes using different accounts.
- Verify vote counts and election results.
This project demonstrates several useful blockchain security concepts:
The contract maintains voting status so that a wallet cannot cast multiple votes during the same election.
Administrative functions should only be callable by the authorized administrator account.
Voting-related state is stored on the blockchain, making contract activity auditable through blockchain transactions and state queries.
Election operations should only be allowed during the appropriate stage of the election lifecycle.
Candidate IDs, voter addresses, and other contract inputs should be validated before modifying election state.
This system should not be considered a production-ready electronic voting platform.
Important limitations include:
- A blockchain wallet does not inherently prove the real-world identity of a voter.
- Public blockchain transactions may expose voting-related information.
- Wallet ownership can be lost or compromised.
- Smart contract vulnerabilities could affect election integrity.
- Gas fees and blockchain performance can limit scalability.
- Voter privacy requires additional cryptographic and architectural mechanisms.
- Real elections require legal, organizational, accessibility, identity, auditing, and security requirements beyond this prototype.
This project can be used to demonstrate:
- Solidity smart contract development
- Ethereum-based application architecture
- Blockchain state management
- Access control
- Smart contract testing
- Decentralized application concepts
- Transparent transaction processing
- Basic e-voting system design
Possible extensions include:
- Web3 frontend using React
- MetaMask wallet integration
- Event-based election monitoring
- Multiple election support
- Improved role-based access control
- Candidate metadata management
- Automated deployment workflows
- Additional security tests
- Gas optimization
- Privacy-preserving voting mechanisms
- More comprehensive frontend result visualization
npm install
npx hardhat compile
npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.js --network localhostThis project is provided for educational and academic purposes.
You may add an open-source license such as the MIT License if you intend to distribute or modify the project under those terms.
Rohit Singh
GitHub: https://github.com/rohitsingh83
This repository is an educational blockchain voting prototype. It should not be used to conduct real governmental, institutional, public, or legally binding elections without extensive additional security, privacy, identity, accessibility, compliance, and auditing measures.
