This smart contract is designed to create a voiting with a list of candidates, with the ability for any other users to choose a winner.
To participate in the voting user should deposit 0.01ETH.
The winner of the vote takes the entire amount collected, minus the commission.
For run unit-tests use cmd it will run npx hardhat coverage
:
npm test
To deploy VoiceEngine smart-contract at localhost you should use this steps:
- Run hardhat node:
npx hardhat node
- Deploy Contract:
npx hardhat run scripts/deploy.js --network localhost
- Add new env variable with deployed contract address
- createVote
❯ npx hardhat createVote --help
Hardhat version 2.9.9
Usage: hardhat [GLOBAL OPTIONS] createVote --candidates <STRING> [--duration <STRING>] --index <STRING>
OPTIONS:
--candidates Candidates addresses
--duration By default duration == 3 days, but could be config through this param
--index Index of voting
createVote: Create new voiting
- makingVoting
❯ npx hardhat makeVoting --help
Hardhat version 2.9.9
Usage: hardhat [GLOBAL OPTIONS] makeVoting --candidate <STRING> --index <STRING>
OPTIONS:
--candidate Choosen candidate address
--index Index of voting
makeVoting: Making a vote
For global options help run: hardhat help
- taxWithdraw
❯ npx hardhat taxWithdraw --help
Hardhat version 2.9.9
Usage: hardhat [GLOBAL OPTIONS] taxWithdraw --addr <STRING> --amount <STRING>
OPTIONS:
--addr Address of funds receive
--amount Amount of withdraw funds
taxWithdraw: Tax withdraw
For global options help run: hardhat help
- finishVote
❯ npx hardhat finishVote --help
Hardhat version 2.9.9
Usage: hardhat [GLOBAL OPTIONS] finishVote --index <STRING>
OPTIONS:
--index Index of Voiting
finishVote: Finish the voiting
For global options help run: hardhat help
- Create new voting by owner with duration 60s
npx hardhat createVote --index 0 --candidates 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2, 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db --duration 60 --network localhost
2. Make a vote for first candidate
npx hardhat makeVoting --index 0 --candidate 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 --network localhost
npx hardhat taxWithdraw --amount 0.001 --addr 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --network localhost
4. Finish the voiting after duraction expire
npx hardhat finishVote --index 0 --network localhost
To deploy this smart-contract ot rinkeby network, just change env vars:
- CONTRACT_ADDRESS -> address of deployed contract to rinkeby
- PRIVATE_KEY -> private key of your rinkeby account (e.g. metamask)
- PROD_ALCHEMY_KEY -> private api key of Alchemy
- STAGING_ALCHEMY_KEY -> private api URL of Alchemy
Run cmd:
npx hardhat run scripts/deploy.js --network rinkeby
To run tasks, just change network value to rinkeby
This contract was deployed to Rinkeby test network https://rinkeby.etherscan.io/
Contract address:
0x86b3Acc1a5FD437A9fe6664aa4eE161b34888B73