Built a voting ballot application with 4 NFL Teams such that there is a chairperson who is authorized to register voters. Voters have the permission to vote only after the registration process.
The smart contract used is based on the example in solidity docs
- Chairperson registers accounts to vote
- No other account can register accounts to vote
- Can't register already registered user
- Unregistered account can't vote
- Registered accounts cannot vote twice
- Can't vote a person who is not there
- State change rules
- Save start time as a state variable
- NodeJs
- Metamask (3.14.1)
- Truffle (v4.0.4)
- Clone the repository to a local folder
- Go to the cloned folder using command line
- Execute truffle compile
- Open a new command line and execute truffle develop to start the blockchain network
- In the old terminal execute truffle migrate --reset
- Execute truffle test
This should print the following in the console
Contract: BallotContract ✓ contract deployment ✓ valid users registration ✓ valid voting ✓ validate winner ✓ valid votes ✓ should NOT accept unauthorized registration ✓ should NOT register already registered user ✓ should NOT vote from unauthorized account ✓ should NOT vote twice ✓ should NOT vote unknown person
10 passing
- Now to start the nodeJs server execute npm run dev
- This should start the front end of the application at localhost:3000
- Open Metamask in your chrome browser and enter the key phrase you got after executing truffle develop
- Now connect to private network using http://127.0.0.1:9545 and create as many accounts as you want
- Now you should be in the first account in the metamask and register all other accounts
- Now to cast vote from the account 2 change the account in Metamask from account 1 to account 2 and then click vote.
- To vote from any account switch to that account in metamask and then click vote
- Finally, after voting you can click declare winner
Note:
- To deploy a new instance of the contract exit the npm server and then execute truffle migrate --reset and then start the server again.
- The contract is deployed from account[0] i.e the first account in the metamask.