A decentralized voting application built on the Sway language, designed to allow users to vote on dynamically managed options. Each vote counts toward a specified option ID, and users are restricted to voting only once. The dApp leverages Fuel's blockchain platform, ensuring transparency, immutability, and security of the voting process.
- Dynamic Voting Options: Supports any number of voting options by storing votes in a dynamic map. No redeployment is required when adding or removing options.
- Single Vote per User: Ensures that each user can only vote once, preventing duplicate voting.
- Vote Count Tracking: Allows users to view vote counts for specific options or get a full summary of all voting results.
- Check Voting Status: Users can check if they have already cast their vote.
The contract consists of three main components:
- Vote Counts: Stores a dynamic
Map
of option IDs with corresponding vote counts, allowing flexibility in the number of voting options. - Voter Records: Tracks each user's voting status to prevent multiple votes from the same user.
- Voting and Query Functions: Functions for casting votes, retrieving vote counts, and checking voting status.
- Fuelup (Fuel toolchain installer for Sway)
If you prefer to work locally and have the Fuel toolchain installed, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/dynamic-voting-dapp cd dynamic-voting-dapp
-
Build the project:
forc build
-
Deploy the contract on the Fuel testnet or a local Fuel node.
If you don't want to go through the installation process, you can easily experiment with the contract on the Sway Playground.
- Simply visit the link above to load the contract directly into the Sway Playground.
- The Playground provides an interactive environment where you can test and deploy the contract on the testnet without installing anything locally.
-
Cast a Vote:
- Call
cast_vote(option_id)
with the option ID to vote for.
- Call
-
Check Vote Count:
- Call
get_vote_count(option_id)
to see the vote count for a specific option. - Alternatively, call
get_all_vote_counts()
for a summary of all votes.
- Call
-
Check Voting Status:
- Call
has_voted()
to see if the user has already voted.
- Call