The TokenizedBallot
smart contract facilitates tokenized voting using the ERC-20 token MyToken
. Leveraging the OpenZeppelin libraries, it implements delegation, voting, and access control features. The contract takes a snapshot of voting power at deployment, preventing users from obtaining additional power post-snapshot. Users can cast votes with a limit, tracked through a remainingVotingPower map, ensuring fairness and transparency in the voting process.
-
Ethers: Used for interacting with Ethereum smart contracts and the Ethereum blockchain. Link to Ethers
-
Hardhat: Employed as the development environment for compiling, testing, and deploying smart contracts. Link to Hardhat
-
OpenZeppelin Contracts: Integrated for utilizing standardized and secure smart contract components, including ERC-20 and access control. Link to OpenZeppelin Contracts
-
Clone the Repository:
git clone https://github.com/wendecoder/TokenizedBallot.git cd your-repo
-
Install Dependencies:
npm install
-
Compile Smart Contracts
npx hardhat compile
-
Set Up Environment Variables: Create a
.env
file in the project root with the following variables:PRIVATE_KEY=your_private_key RPC_ENDPOINT_URL=your_rpc_endpoint_url WALLET_ADDRESS_TO_MINT_TO=your_wallet_address MY_TOKEN_CONTRACT_ADDRESS=your_my_token_contract_address TOKENIZED_BALLOT_CONTRACT_ADDRESS=your_tokenized_ballot_contract_address
-
Run the Scripts:
-
Deploy MyToken contract:
npx ts-node scripts/deployMyToken.ts
-
Deploy TokenizedBallot contract:
npx ts-node scripts/deployTokenizedBallot.ts Proposal1 Proposal2 Proposal3
Note: Replace "Proposal1", "Proposal2", "Proposal3" with your actual proposal names.
-
Giving voting tokens for voters:
npx ts-node scripts/giveVotingTokens.ts <wallet_to_mint_to> <amount_of_tokens>
-
Delegating vote:
npx ts-node scripts/delegateVote.ts <address_to_delegate_to> <wallet_private_key>
-
Casting vote:
npx ts-node scripts/castVote.ts <wallet_private_key> <index_of_proposal> <amount_of_voting_power_to_cast>
-
Checking voting power left:
npx ts-node scripts/checkVotePower.ts <wallet_private_key>
-
Querying result:
npx ts-node scripts/queryResult.ts
-
Happy Voting