During this workshop, we will build a smart contract that handles voting with multiple users calling the contract to vote. This demo is DAO-esque, demonstrating many of features that would be used in a full DAO voting contract.
We are writing a smart contract for a group of people who love numbers! They want to be able to keep track of the group's current favorite number and vote on new favorite numbers. The contract will use a governance token to allocate votes, and will allow users to deposit tokens, withdraw tokens, vote on a new favorite number, and execute the contract to count the votes and set a new favorite number.
- Download this repo
- Get set up
- Set up your editor
- Check out the Sway primer (optional, but recommended)
- Build the Token contract
- Build the Voting contract
- Expand the scope of the demo and keep working (optional!)
-
Install
cargo
usingrustup
Mac and Linux:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Check for correct setup:
$ cargo --version cargo 1.62.0
-
Install
forc
usingfuelup
Mac and Linux:
curl --proto '=https' --tlsv1.2 -sSf \ https://fuellabs.github.io/fuelup/fuelup-init.sh | sh
-
Check for correct setup:
$ forc --version forc 0.18.1
if that doesn't work
You are welcome to use your editor of choice.
Here is a little list of ideas of how you might expand this example.
- Add an additional function to the ABI that allows users to unlock votes and put them back into their balance
- Give a reward to the users who voted for the winning number
- Change the Voting contract so that it accepts proposals for new favorite numbers, rather than using [0, 99)
- Expand the scope of what the group votes on---it could be something other than a favorite number