Coder Social home page Coder Social logo

ompals / tokenizedballot-week3-encode Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 963 KB

Tokenized Ballot Smart Contract based on ERC20 and ERC20Votes

Solidity 18.29% TypeScript 81.71%
ballot ethereum ethers hardhat mocha smart-contracts tokenization typescript

tokenizedballot-week3-encode's Introduction

Tokenized Ballot Smart Contract based on ERC20 and ERC20Votes

Introduction

In the decentralized voting, ballot smart contract works like atomic voting. From an account, one can only vote once. While in tokenized ballot contract, from an account, one can vote some amount of tokens to some proposals. We achieve it by composing an ERC20Vote contract into the modified version of Ballot Smart Contract, which we call it "TokenizedBallot" contract. The delegate function works differently with tokenized ballot. One can delegate some amount of ERC20Vote tokens to some other account. So, the voting power doesn't go to some other account unlike simple ballot.

Usage

  1. Clone this repo
  2. Create a .env file in the root folder
  3. Copy the following to the .env file:
MNEMONIC=""

# Used for contract deployment 
PRIVATE_KEY=""

# Used for testing functionalities
PRIVATE_KEY1=""
PRIVATE_KEY2=""
PRIVATE_KEY3=""
PRIVATE_KEY4=""
PRIVATE_KEY5=""

INFURA_API_KEY=""
INFURA_API_SECRET=""
ALCHEMY_API_KEY=""
ETHERSCAN_API_KEY=""

GOERLI_RPC_URL=""
ALCHEMY_RPC_URL=""
POKT_RPC_URL=""
RINKEBY_RPC_URL=""
  1. Install all the dependencies by running the following command in your terminal:
yarn install
  1. Compile all the contracts. This will add all the abi of contracts and make a typescript interface to access the contracts from scripts with the help of TypeChain.
yarn hardhat compile
  1. Now, let's understand the scripts and deploy and use contracts:

    • First we wil require to deploy the MyToken contract - MTK. Run the following command:
    yarn hardhat run scripts\DeployMyToken.ts --network goerli
    

    This will deploy the contract to the Goerli testnet.

    • Then we will setup our testnet accounts to have some MTKs. This will give this account voting power in TokenizedBallot context later on after we deploy it. Run the following commands:
    yarn hardhat run scripts\MintVotingTokens.ts --network goerli
    yarn hardhat run scripts\DelegateVotes.ts --network goerli
    yarn hardhat run scripts\SetupVotingAccounts.ts --network goerli
    
    • After having all the accounts setup for the voting, now we will deploy the TokenizedBallot Contract. Due to it's current implementation, the target block is only assigned during construction time and it cannot be changed. So, if we have deployed the Tokenized Ballot before minting/delegating/transferring MTKs, then in all the accounts, votingPower should have remained 0, even after minting/delegating/transferring to that accoumt. So now, we will deploy it. Run the following command:
    yarn hardhat run scripts\DeployTokenizedBallot.ts --network goerli
    
    • Next we will be having some voting time. The script: scripts\CastVote.ts contains the voting process by 5 voters we added private keys of earlier in the .env file.
    yarn hardhat run scripts\CastVote.ts --network goerli
    
    • We will check which proposal won by running the query script:
    yarn hardhat run scripts\WinningProposalQuery.ts --network goerli
    

Link to the document where all the above transactions were reported: ETHDenver Week 3 Group Assignment

This is how the overall workflow for TokenizedBallot looks like... Many things are hardcoded, which would be made easier to operate in future. A beautiful UI would also be something to consider.

tokenizedballot-week3-encode's People

Contributors

ompals avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.