Skip to content

webtester0/voice-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Voice Engine

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.

Description

Unit tests

For run unit-tests use cmd it will run npx hardhat coverage:

npm test

Coverege 100%

Deploy and Tasks

Hardhat localhost

To deploy VoiceEngine smart-contract at localhost you should use this steps:

  1. Run hardhat node:
npx hardhat node
  1. Deploy Contract:
npx hardhat run scripts/deploy.js --network localhost
  1. Add new env variable with deployed contract address

Tasks decription

  1. 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
  1. 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
  1. 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
  1. 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

Examples of interactions with deployed smart-contract at localhost network

  1. 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

3. Tax withdraw

npx hardhat taxWithdraw --amount 0.001 --addr 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --network localhost

4. Finish the voiting after duraction expire

npx hardhat finishVote --index 0 --network localhost

Voice Engine in Rinkeby Testnet Network

Deploy to rinkeby

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

Example of deployed smart-contract

This contract was deployed to Rinkeby test network https://rinkeby.etherscan.io/

Contract address: 0x86b3Acc1a5FD437A9fe6664aa4eE161b34888B73

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published