Build a voting contract with Solidity structs, mappings and events
8 steps · about 1 h 47 min · Intermediate
- Walk through the Ballot voting example (tutorial, Solidity documentation, 25 min)
The official example that this whole path rebuilds and extends.
- Lay out state variables, functions, modifiers and events (reference, Solidity documentation, 10 min)
Names each building block before you combine them.
- Pick value types, structs and mappings for votes (reference, Solidity documentation, 25 min)
Explains storage versus memory and why mappings cannot be iterated.
- Practise declaring and updating structs (interactive, Solidity by Example, 8 min)
Small editable snippets for struct arrays.
- Practise nested mappings for voter records (interactive, Solidity by Example, 8 min)
Shows default values and deleting entries.
- Guard functions with modifiers (interactive, Solidity by Example, 8 min)
Restricts who may give the right to vote.
- Emit events for every vote (interactive, Solidity by Example, 8 min)
Lets off-chain apps follow the vote without reading storage.
- Deploy and call the contract in Remix (reference, Remix documentation, 15 min)
Runs the contract in a browser sandbox with test accounts.