Skip to content

Commit a543844

Browse files
committed
Updated Readme file
1 parent 3c155e4 commit a543844

File tree

3 files changed

+113
-7
lines changed

3 files changed

+113
-7
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"solidity.compileUsingRemoteVersion": "v0.5.17+commit.d19bba13"
3+
}

README.md

+106-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,111 @@
1-
# Ballot Contract
1+
# Web3 Ballotsystem
22

3-
Demo smart contract to illustrate how voting may work on the blockchain
3+
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.
4+
5+
## Table of Contents
6+
- [Introduction](#introduction)
7+
- [Features](#features)
8+
- [Process](#process)
9+
- [Installation](#installation)
10+
- [Steps to Implement the Ballot](#steps-to-implement-the-ballot)
11+
- [Contributing](#contributing)
12+
13+
## Introduction
14+
15+
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.
16+
17+
## Features
18+
19+
- **Decentralized Voting**: Votes are cast and counted on the blockchain, ensuring transparency.
20+
- **Immutable Records**: Once a vote is cast, it cannot be altered or deleted.
21+
- **Simple Interface**: Easy to understand and interact with, suitable for educational purposes.
422

523
## Process
624

7-
1. constructor
8-
2. addVoter()
9-
3. startVote()
10-
4. countVote()
25+
1. **Proposal Submission**: Users can submit proposals that others will vote on.
26+
2. **Voting**: Users cast their votes for the proposals.
27+
3. **Vote Counting**: The smart contract counts the votes and determines the outcome based on the votes cast.
28+
29+
## Installation
30+
31+
To install and deploy the Ballot Contract, follow these steps:
32+
33+
1. **Clone the Repository**:
34+
```sh
35+
git clone https://github.com/yourusername/ballot-contract.git
36+
cd ballot-contract
37+
```
38+
2. **Install Ganache** from [Ganache](https://www.trufflesuite.com/ganache).
39+
3. **Open Ganache** and choose “Quick Start”.
40+
4. **Check for Host Name** - Ensure it is set to `127.0.0.1`. If not, change it to the loopback address.
41+
5. **Set Server Port Number** to `8545`.
42+
6. **Set Account & Keys** - You can set Account Default Balance and Total Accounts to Generate (leave the default settings for now).
43+
7. **Set the Chain** - Configure Gas and Gas Limit, then click on save and restart.
44+
8. **Get 10 Accounts** ready for your private blockchain.
45+
9. **Install MetaMask**:
46+
- Open Chrome and go to [MetaMask](https://metamask.io/).
47+
- Add the MetaMask Extension to Chrome.
48+
- Add the localhost network manually:
49+
- Network Name: Any name you choose
50+
- New RPC URL: `http://localhost:8545`
51+
- ChainID: `1337` (default for port 8545)
52+
- Currency Symbol: `ETH`
53+
- Block Explorer URL: (optional, e.g., `https://etherscan.io`)
54+
- Save the settings.
55+
10. **Deploy the Contract**:
56+
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
57+
11. **Create MetaMask Accounts**:
58+
- Import private keys from Ganache listed accounts.
59+
- Create four accounts (or five):
60+
- Admin (manages the ballot)
61+
- Zoe (voter)
62+
- Ellie (voter)
63+
- Peter (voter)
64+
65+
66+
## Steps to Implement the Ballot
67+
68+
9. **Create MetaMask Accounts**:
69+
- Import private keys from Ganache listed accounts.
70+
- Create four accounts:
71+
- Admin (manages the ballot)
72+
- Zoe (voter)
73+
- Ellie (voter)
74+
- Peter (voter)
75+
10. **Copy and Paste ballot.sol**:
76+
- Get the contract from [Ballot System](https://github.com/needanewone/ballotsystem).
77+
- Paste it into [Remix IDE](https://remix.ethereum.org/).
78+
- Switch to the Admin MetaMask account before compiling.
79+
- Compile the contract.
80+
11. **Deploy the Contract**:
81+
- In Remix, switch to the Admin’s MetaMask wallet account.
82+
- Deploy the Ballot contract.
83+
- Set up a proposal (e.g., "Should we re-elect the Chairman?").
84+
12. **Set Up Ballot Manager**:
85+
- Go to [Ballot Manager](https://needanewone.github.io/ballotsystem/).
86+
- As Admin, fill in the Ballot Official Name and the Proposal. Click “Go”.
87+
13. **Add Voters**:
88+
- As Admin, add voters (e.g., Alice, Bob, and Carol) by adding their wallet addresses and names.
89+
14. **Start Voting**:
90+
- As Admin, start the vote by pressing “Start Voting”.
91+
15. **Vote**:
92+
- Let each voter vote at [Ballot Voting](https://needanewone.github.io/ballotsystem/vote.html).
93+
- Switch MetaMask account for each voter.
94+
- Enter the Ballot Address and click [Go].
95+
- Retrieve ballot details and vote [Yes] or [No].
96+
16. **Check Voter Status**:
97+
- Switch back to Ballot Manager as Admin.
98+
- Check the status of the voters.
99+
17. **End Voting and Get Results**:
100+
- As Admin, end the voting.
101+
- Display the results.
102+
- View the total number of voters and total votes cast.
103+
104+
**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.
105+
106+
## Contributing
107+
108+
Contributions are welcome! Please fork the repository and submit a pull request to contribute.
109+
110+
11111

vote.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ <h1>Vote</h1>
6868
var ballotContract;
6969
var ballotByteCode;
7070
var Ballot;
71-
var ballotABI = [{"constant":false,"inputs":[],"name":"startVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalVoter","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposal","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_choice","type":"bool"}],"name":"doVote","outputs":[{"name":"voted","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ballotOfficialAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"voterRegister","outputs":[{"name":"voterName","type":"string"},{"name":"voted","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"endVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_voterAddress","type":"address"},{"name":"_voterName","type":"string"}],"name":"addVoter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ballotOfficialName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalVote","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"finalResult","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_ballotOfficialName","type":"string"},{"name":"_proposal","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"voter","type":"address"}],"name":"voterAdded","type":"event"},{"anonymous":false,"inputs":[],"name":"voteStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"finalResult","type":"uint256"}],"name":"voteEnded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"voter","type":"address"}],"name":"voteDone","type":"event"}];
71+
var ballotABI = [
72+
{"constant":false,
73+
"inputs":[],
74+
"name":"startVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalVoter","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposal","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_choice","type":"bool"}],"name":"doVote","outputs":[{"name":"voted","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ballotOfficialAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"voterRegister","outputs":[{"name":"voterName","type":"string"},{"name":"voted","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"endVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_voterAddress","type":"address"},{"name":"_voterName","type":"string"}],"name":"addVoter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ballotOfficialName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalVote","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"finalResult","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_ballotOfficialName","type":"string"},{"name":"_proposal","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"voter","type":"address"}],"name":"voterAdded","type":"event"},{"anonymous":false,"inputs":[],"name":"voteStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"finalResult","type":"uint256"}],"name":"voteEnded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"voter","type":"address"}],"name":"voteDone","type":"event"}];
7275
var voterTable;
7376

7477
$( document ).ready(function() {

0 commit comments

Comments
 (0)