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.
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.
- 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.
- Proposal Submission: Users can submit proposals that others will vote on.
- Voting: Users cast their votes for the proposals.
- Vote Counting: The smart contract counts the votes and determines the outcome based on the votes cast.
To install and deploy the Ballot Contract, follow these steps:
- Clone the Repository:
git clone https://github.com/yourusername/ballot-contract.git cd ballot-contract
- Install Ganache from Ganache.
- Open Ganache and choose “Quick Start”.
- Check for Host Name - Ensure it is set to
127.0.0.1
. If not, change it to the loopback address. - Set Server Port Number to
8545
. - Set Account & Keys - You can set Account Default Balance and Total Accounts to Generate (leave the default settings for now).
- Set the Chain - Configure Gas and Gas Limit, then click on save and restart.
- Get 10 Accounts ready for your private blockchain.
- 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.
- 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
- 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)
- Create MetaMask Accounts:
- Import private keys from Ganache listed accounts.
- Create four accounts:
- Admin (manages the ballot)
- Zoe (voter)
- Ellie (voter)
- Peter (voter)
- 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.
- 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?").
- Set Up Ballot Manager:
- Go to Ballot Manager.
- As Admin, fill in the Ballot Official Name and the Proposal. Click “Go”.
- Add Voters:
- As Admin, add voters (e.g., Alice, Bob, and Carol) by adding their wallet addresses and names.
- Start Voting:
- As Admin, start the vote by pressing “Start Voting”.
- 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].
- Check Voter Status:
- Switch back to Ballot Manager as Admin.
- Check the status of the voters.
- 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.
Contributions are welcome! Please fork the repository and submit a pull request to contribute.