pistomat / decentralized-voting-system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VotingApp

Description

VotingApp is a simple decentralized voting system implemented in Solidity. The smart contract allows eligible voters to vote for candidates in an election and prevents double voting. The VotingApp contract is deployed on the Ethereum blockchain and provides various functionalities for voter registration, candidate registration, casting votes, and winner declaration.

Features

  1. Voter Registration: Only the owner of the contract can register voters. Only registered voters are able to vote.
  2. Candidate Registration: Only the owner of the contract can add candidates.
  3. Voting: Registered voters can vote for a candidate. Each voter is only able to vote once. Attempting to vote again results in an error.
  4. Winner Declaration: The contract determines the winner of the election based on the candidate who achieved the most votes the first.
  5. Election Duration: The minimum duration of an election is 1 day and the maximum duration of an election is 1 year.

Install

Install Foundry with foundryup:

curl -L https://foundry.paradigm.xyz | bash
foundryup

Run tests

forge test

Deploy

FOUNDRY_PROFILE=optimized forge script VotingAppDeployScript --verify --multi --broadcast

Deployments By EVM Chain

The VotingApp contract has been deployed on the following EVM chains:

Network VotingApp
Goerli [0x0000363AeF5c879eFf0339725989D7953BE35716](https://goerli.etherscan.io/address/0x0000363AeF5c879eFf0339725989D7953BE35716#code)
Sepolia [0x0000363AeF5c879eFf0339725989D7953BE35716](https://sepolia.etherscan.io/address/0x0000363AeF5c879eFf0339725989D7953BE35716#code)
Polygon [0x0000363AeF5c879eFf0339725989D7953BE35716](https://polygonscan.com/address/0x0000363AeF5c879eFf0339725989D7953BE35716#code)

Note on Winner Ties

Please note that in the case of a tie (i.e., multiple candidates receiving the same top number of votes), the winner is determined as the first candidate who reached the top number of votes. This design choice means that the system is susceptible to front-running attacks. In a front-running scenario, an entity could potentially observe a transaction that's been broadcast to the network (but not yet confirmed), and then submit their own transaction with a higher gas fee to secure priority in the transaction queue, thus changing the outcome of the election. However, this model was adopted to keep gas costs low and maintain the simplicity of this app. More sophisticated solutions to handle ties or prevent front-running attacks are beyond the scope of this simple demonstration app. It's important to consider these aspects if you're planning to use this code for more substantial applications or purposes.

About

License:MIT License


Languages

Language:Solidity 100.0%