Build a voting contract with Solidity structs, mappings and events

8 steps · about 1 h 47 min · Intermediate

  1. Walk through the Ballot voting example (tutorial, Solidity documentation, 25 min)

    The official example that this whole path rebuilds and extends.

  2. Lay out state variables, functions, modifiers and events (reference, Solidity documentation, 10 min)

    Names each building block before you combine them.

  3. Pick value types, structs and mappings for votes (reference, Solidity documentation, 25 min)

    Explains storage versus memory and why mappings cannot be iterated.

  4. Practise declaring and updating structs (interactive, Solidity by Example, 8 min)

    Small editable snippets for struct arrays.

  5. Practise nested mappings for voter records (interactive, Solidity by Example, 8 min)

    Shows default values and deleting entries.

  6. Guard functions with modifiers (interactive, Solidity by Example, 8 min)

    Restricts who may give the right to vote.

  7. Emit events for every vote (interactive, Solidity by Example, 8 min)

    Lets off-chain apps follow the vote without reading storage.

  8. Deploy and call the contract in Remix (reference, Remix documentation, 15 min)

    Runs the contract in a browser sandbox with test accounts.