This smart contract will allow you to hold elections using the blockchain to record results. It is only a starter template, more checks-and-balances would need to be added for a serious election.
A Hardhat network is used to deploy and test the contract locally.
Clone the repository:
git clone https://github.com/PatrickMalloy/election-ethereum.git
Change into the new directory and install dependencies
cd election-ethereum
npm install
Start a Hardhat local node in a terminal
npx hardhat node
In a new terminal run the tests using the following:
npx hardhat --network localhost test
or
npm run test
- Allow the owner address to be passed in/changed
- On startVoting(), add a duration parameter for when the voting will end, e.g. 24 hours
- Verify there are candidates added before voting can start
- Don't allow the voting to be done more than once
- Create a whitelist of valid wallet addresses that can vote
- Allow a list of candidates to be added at once, instead of individually