Basic On-Chain Voting System

A simplified, secure smart contract for decentralized voting, preventing users from voting multiple times and tracking results transparently.

Thumbnail proyek Basic On-Chain Voting System

Project Summary

This project implements a foundational voting mechanism using Solidity. It ensures that each unique address can cast only one vote, preventing manipulation. The contract registers two candidates upon deployment and securely increments the vote count, providing immediate and auditable results.

My Role

Smart Contract Developer: Responsible for designing the core voting logic, including the single-vote restriction and candidate initialization.

Challenges

The primary challenge was implementing a secure method to restrict voting to a single instance per user (address) while maintaining simplicity and gas efficiency.

Solution & Implementation

Implemented a boolean `mapping(address => bool) public hasVoted` which is checked using `require(!hasVoted[msg.sender], ...)` at the start of the `vote()` function, guaranteeing one-time participation.

Main Features

  • Single-Vote Restriction (One Address, One Vote)
  • On-Chain Vote Tallying
  • Transparent Results (View Functions)
  • Basic Candidate Registration

Technology

SoliditySmart ContractGovernanceDApp

Gallery