This project implements a decentralized voting system using Ethereum blockchain technology. It allows for creating elections, adding candidates, and securely casting votes.
- Create new elections
- Add candidates to an election
- Cast votes securely
- View election results in real-time
- Ensures one vote per address
- Transparent and immutable voting records
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed
- Truffle framework installed (
npm install -g truffle
) - Ganache for local blockchain simulation Download Ganache
- MetaMask browser extension for interacting with the dApp Download MetaMask
-
Clone the repository:
git clone https://github.com/SlimenFellah/Decentralized-Voting-System.git
cd Decentralized-Voting-System
-
Install dependencies:
npm install
-
Start Ganache and ensure it's running on
http://127.0.0.1:7545
-
Compile and migrate the smart contracts:
truffle compile
truffle migrate --reset
-
Start the development server:
npx webpack serve
-
Connect MetaMask to your local Ganache network (usually
http://127.0.0.1:7545
) -
Import one of the Ganache accounts into MetaMask using the private key
-
Navigate to
http://localhost:8080
in your browser -
Use the interface to add candidates and cast votes
-
View the election results in real-time
The main smart contract Voting.sol
includes the following key functions:
addCandidate(string memory _name)
: Add a new candidate to the electionvote(uint _candidateId)
: Cast a vote for a specific candidategetVoteCount(uint _candidateId)
: Get the number of votes for a specific candidate
To make changes to the smart contract:
- Modify
contracts/Voting.sol
- Compile and migrate the contract:
truffle migrate --reset
- Update the ABI in the frontend if necessary
To modify the frontend:
- Edit files in the
src
directory - The changes will be automatically reflected if you're running the webpack dev server
Run the test suite:
truffle test
Contributions to the Decentralized Voting System are welcome. Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.