A Solidity-based modular voting system designed for flexibility and extensibility. This project enables decentralized voting with support for multiple voter registry mechanisms and a factory pattern for ballot creation.
- ๐งโ๐ป Features
- ๐ Architecture Overview
- ๐จ Technology Stack
- ๐๏ธ Project Structure
- ๐ How to Use This Repo
- ๐ฎ Future Improvements
- ๐ License
- Modular Voter Registries: Supports multiple voter registry mechanisms:
- Address-Based Voter Registry: Voters are registered by their addresses.
- Token-Based Voter Registry: Voting eligibility is determined by token ownership.
- Ballot Factory: Simplifies the creation of new ballots with predefined proposals.
- Event Transparency: Emits detailed events for all critical operations, such as vote casting, voter registration, and ballot creation.
- Secure Voting: Ensures only eligible voters can vote and prevents double voting.
- Result Retrieval: Provides a mechanism to retrieve voting results after the voting period ends.
-
Factory Pattern for Ballot Creation:
- The
BallotFactory
contract is used to create multipleBallot
instances dynamically. - This pattern centralizes the creation logic, making it easier to manage and scale the system.
- The
-
Decoupled Voting Logic:
- The voting logic in the
Ballot
contract is completely separated from the voter registry logic. - This ensures that the
Ballot
contract focuses solely on managing proposals and votes, while the voter registry handles eligibility and voting status.
- The voting logic in the
-
Strategy Pattern for Voter Registries:
- The
IVoterRegistry
interface defines a standard for voter registries. - Multiple implementations, such as
AddressBasedVoterRegistry
andTokenBasedVoterRegistry
, represent different strategies for determining voter eligibility. - The
Ballot
contract interacts with the voter registry through theIVoterRegistry
interface, allowing the system to switch between different voter registry strategies without modifying theBallot
contract. - This modular approach enables the system to support additional voter registry mechanisms in the future.
- The
IVoterRegistry
: Interface defining the voter registry contract structure.AddressBasedVoterRegistry
: Implements voter registration based on addresses.TokenBasedVoterRegistry
: Implements voter registration based on token ownership.Ballot
: Core voting contract where proposals are defined and votes are cast.BallotFactory
: Factory contract for creating and managing multipleBallot
instances.
- The
Ballot
contract interacts with a voter registry (IVoterRegistry
) to validate voter eligibility and mark voters as having voted. - The
BallotFactory
contract creates newBallot
instances, linking them to a specific voter registry and proposal set. - The modular design allows the system to support additional voter registry mechanisms by implementing the
IVoterRegistry
interface.
Technology | Purpose & Advantages |
---|---|
Solidity | A secure and efficient programming language for writing Ethereum-based smart contracts. |
OpenZeppelin | Provides reusable and secure smart contract libraries for access control and security features. |
Remix | A powerful web-based IDE for writing, testing, and deploying smart contracts. |
- Factory Pattern: Simplifies the creation and management of multiple ballots.
- Strategy Pattern: Allows the system to use different voter registry mechanisms (e.g., address-based or token-based) without modifying the core voting logic.
- Event Logging: Implements detailed event logging for all critical operations to enhance transparency and traceability.
The project is organized as follows:
src/
โโโ Ballot.sol # Core voting contract
โโโ BallotFactory.sol # Factory contract for creating ballots
โโโ IVoterRegistry.sol # Interface for voter registries
โโโ AddressBasedVoterRegistry.sol # Address-based voter registry implementation
โโโ TokenBasedVoterRegistry.sol # Token-based voter registry implementation
Follow these steps to set up and deploy the contracts:
- Clone the repository:
git clone https://github.com/your-username/Elektos-DecentralizeBallot.git cd Elektos-DecentralizeBallot
-
Compile the contract using Remix, Foundry, or your preferred deployment tool.
-
Deploy the contract using Remix, Foundry, or your preferred deployment tool.
2.1. Deploy a voter registry contract (e.g., AddressBasedVoterRegistry
or TokenBasedVoterRegistry
).
2.2. Deploy the BallotFactory
contract.
2.3. Use the BallotFactory
to create new Ballot
instances by specifying:
- The voter registry address.
- Proposal details (name, description, and options).
Test the contract using Remix, Foundry, or your preferred deployment tool.
- Frontend Development: Create a user-friendly frontend using React, TypeScript, and Web3.js or ethers.js to interact with the smart contracts. This will include:
- A dashboard for creating and managing ballots.
- Real-time voting updates and results display.
- Integration with wallets like MetaMask for seamless user interaction.
This project is licensed under the GPL-3.0 License. See the LICENSE
file for details.