Voting on a Blockchain: Solidity Contract Codes Explained
This is the 2nd of 5 articles to explore the development of an end-to-end Balloting system on Ethereum. In this article, i will walk through the codes the Balloting system’s Smart Contract, Ballot.sol.
Do check back often as I work on them.
1. Voting on a Blockchain: How it works
2. Voting on a Blockchain: Solidity Contract Codes explained
3. Voting on a Blockchain: DApp Demonstration
4. Voting on a Blockchain: Ballot Management DApp Code Walk-through
5. Voting on a Blockchain: Voting DApp Code Walk-through
Variables of the Contract
struct vote{
address voterAddress;
bool choice;
}
Lines 12 to 15: A vote comprises 2 parts, the wallet address of the voter, and the choice he makes, and aye or a nah. An aye is represented by the value TRUE and a nah, by the value FALSE.
struct voter{
string voterName;
bool voted;
}
Lines 17 to 20: A voter has 3 attributes, his name, and whether or not he has voted.
mapping(uint => vote) private votes;
mapping(address => voter) public voterRegister;