Skip to content

abhijaatx/BlockchainProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Decentralized Voting System on Ethereum

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.

🌟 Features

  • 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

πŸ“‹ Prerequisites

  • Node.js >= 16.x
  • npm or yarn
  • MetaMask or any Web3 wallet
  • Git

πŸš€ Quick Start

1. Clone the repository

git clone <repository-url>
cd evoting

2. Install dependencies

npm install

3. Compile the smart contract

npm run compile

4. Run tests

npm run test

5. Start a local blockchain

npm run node

In a new terminal, deploy the contract to the local network:

npm run deploy:localhost

6. Run the frontend

You can use any static file server to serve the frontend. For example:

npx http-server ./frontend -p 3000

Then open http://localhost:3000 in your browser.

πŸ“ Project Structure

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

πŸ”§ Smart Contract Functions

View Functions

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

Write Functions

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)

🌐 Deployment to Testnets

Prerequisites

  1. Create a .env file 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
  1. Get testnet ETH from faucets:

Deploy to Sepolia

npm run deploy:sepolia

Deploy to Goerli

npm run deploy:goerli

πŸ§ͺ Testing

The 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 test

Run tests with gas reporting:

REPORT_GAS=true npm run test

πŸ“ Smart Contract Events

The contract emits the following events that can be listened to:

  • ElectionCreated: When a new election is created
  • CandidateAdded: When a candidate is added to an election
  • VoteCast: When a vote is cast
  • ElectionActivated: When an election is activated
  • ElectionDeactivated: When an election is deactivated

πŸ”’ Security Considerations

  1. One vote per address: The contract prevents double voting by tracking which addresses have voted
  2. Time restrictions: Voting is only allowed during the defined election period
  3. Admin controls: Only the admin can activate/deactivate elections
  4. Creator permissions: Only the election creator or admin can add candidates
  5. Input validation: All inputs are validated before processing

🎨 Frontend Features

  • 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

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ž Support

If you have any questions or need help, please open an issue in the repository.

πŸ—ΊοΈ Roadmap

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors