Skip to content

fuzailpalnak/dVoting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Voting dApp on Sway

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.

Features

  • 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.

Contract Overview

The contract consists of three main components:

  1. Vote Counts: Stores a dynamic Map of option IDs with corresponding vote counts, allowing flexibility in the number of voting options.
  2. Voter Records: Tracks each user's voting status to prevent multiple votes from the same user.
  3. Voting and Query Functions: Functions for casting votes, retrieving vote counts, and checking voting status.

Setup

Prerequisites

  • Fuelup (Fuel toolchain installer for Sway)

Installation (Optional)

If you prefer to work locally and have the Fuel toolchain installed, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourusername/dynamic-voting-dapp
    cd dynamic-voting-dapp
  2. Build the project:

    forc build
  3. Deploy the contract on the Fuel testnet or a local Fuel node.

Use Sway Playground (No Installation Needed)

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.

Usage

  1. Cast a Vote:

    • Call cast_vote(option_id) with the option ID to vote for.
  2. 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.
  3. Check Voting Status:

    • Call has_voted() to see if the user has already voted.

About

A decentralized voting application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published