Introduction
The voting smart contract shows an example of voting for proposals.
The interface is similar to OpenZeppelin’s Governor contract, but simplified for demonstration. It can easily be extended to cover the whole interface.
To get started, clone pod-sdk github repository and go to examples/voting directory:
Smart contract
The smart contract uses two types from pod’s fast types library:
The voteCount is the total votes (yes or no) for each proposal, and is increased by any voter. Even though this variable is shared between different senders, the order of transactions do not matter because it can only be incremented.
The hasVoted variable stores whether a voter has voted for a proposal or not. Each user can only alter this value for himself (the value is “owned”).
You can find the full smart contract on our github repository here.
You can deploy the smart contract in the same way as in other EVM networks, for example with foundry forge command. We include a deployment script in Voting.s.sol, to use it:
Interfacing with the contract
Creating a proposal
To create a proposal call createProposal on the smart contract passing a deadline, the threshold for the proposal to be considered passed.
You can use the voting client implementation to create a proposal on the smart contract we have deployed:
The client will create the proposal, and wait for votes until the deadline (30 seconds from command execution).
Voting
Voting is done by submitting a castVote smart contract call.
You can try this out by using the voting client:
Remember to replace the PROPOSAL_ID with the second topic of the log on proposal creation.
Listing votes
To list all the votes, use get_verifiable_logs from pod-sdk.