Skip to content

AXC-Git/Web3-Ballotsystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web3 Ballotsystem

This is a demo smart contract designed to illustrate how voting can be conducted on a Web3 app. The Ballot Contract is a fundamental example of decentralized voting, ensuring transparency and immutability of the voting process.

Table of Contents

Introduction

The Ballot Contract demonstrates a basic voting mechanism on the blockchain. It allows users to propose options and vote on them, ensuring each vote is counted and stored securely on the blockchain.

Features

  • Decentralized Voting: Votes are cast and counted on the blockchain, ensuring transparency.
  • Immutable Records: Once a vote is cast, it cannot be altered or deleted.
  • Simple Interface: Easy to understand and interact with, suitable for educational purposes.

Process

  1. Proposal Submission: Users can submit proposals that others will vote on.
  2. Voting: Users cast their votes for the proposals.
  3. Vote Counting: The smart contract counts the votes and determines the outcome based on the votes cast.

Installation

To install and deploy the Ballot Contract, follow these steps:

  1. Clone the Repository:
    git clone https://github.com/yourusername/ballot-contract.git
    cd ballot-contract
  2. Install Ganache from Ganache.
  3. Open Ganache and choose “Quick Start”.
  4. Check for Host Name - Ensure it is set to 127.0.0.1. If not, change it to the loopback address.
  5. Set Server Port Number to 8545.
  6. Set Account & Keys - You can set Account Default Balance and Total Accounts to Generate (leave the default settings for now).
  7. Set the Chain - Configure Gas and Gas Limit, then click on save and restart.
  8. Get 10 Accounts ready for your private blockchain.
  9. Install MetaMask:
    • Open Chrome and go to MetaMask.
    • Add the MetaMask Extension to Chrome.
    • Add the localhost network manually:
      • Network Name: Any name you choose
      • New RPC URL: http://localhost:8545
      • ChainID: 1337 (default for port 8545)
      • Currency Symbol: ETH
      • Block Explorer URL: (optional, e.g., https://etherscan.io)
      • Save the settings.
  10. Deploy the Contract: Ensure you have a development environment set up (like Remix IDE or Hardhat) and deploy the contract.I personally use Remix IDE to deploy the contract in a network
  11. Create MetaMask Accounts:
    • Import private keys from Ganache listed accounts.
    • Create four accounts (or five):
      • Admin (manages the ballot)
      • Zoe (voter)
      • Ellie (voter)
      • Peter (voter)

Steps to Implement the Ballot

  1. Create MetaMask Accounts:
    • Import private keys from Ganache listed accounts.
    • Create four accounts:
      • Admin (manages the ballot)
      • Zoe (voter)
      • Ellie (voter)
      • Peter (voter)
  2. Copy and Paste ballot.sol:
    • Get the contract from Ballot System.
    • Paste it into Remix IDE.
    • Switch to the Admin MetaMask account before compiling.
    • Compile the contract.
  3. Deploy the Contract:
    • In Remix, switch to the Admin’s MetaMask wallet account.
    • Deploy the Ballot contract.
    • Set up a proposal (e.g., "Should we re-elect the Chairman?").
  4. Set Up Ballot Manager:
    • Go to Ballot Manager.
    • As Admin, fill in the Ballot Official Name and the Proposal. Click “Go”.
  5. Add Voters:
    • As Admin, add voters (e.g., Alice, Bob, and Carol) by adding their wallet addresses and names.
  6. Start Voting:
    • As Admin, start the vote by pressing “Start Voting”.
  7. Vote:
    • Let each voter vote at Ballot Voting.
    • Switch MetaMask account for each voter.
    • Enter the Ballot Address and click [Go].
    • Retrieve ballot details and vote [Yes] or [No].
  8. Check Voter Status:
    • Switch back to Ballot Manager as Admin.
    • Check the status of the voters.
  9. End Voting and Get Results:
    • As Admin, end the voting.
    • Display the results.
    • View the total number of voters and total votes cast.

IMPORTANT NOTES: If you want to repeat the voting process, restart Ganache and MetaMask (for ALL involved accounts), and re-copy, paste, and compile ballot.sol beforehand.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request to contribute.