DAO Smart Contract for donation were you can propose the then propose pass and everyone will be given token to vote. If it success then the address we have provide ether will deposit.
-There are four Contract.
- Nappy Token
- TimeLock
- Governance
- Locker
- Token Name: Nappy Token
- Token Symbol: NPY
- Nappy Token will use to mint token and transfer to voter for use in voting.
- First owner will mint the token. There is no fixed supply to mint the token.
- This contract will also use for delegate the tokens. User will have to call delegate() function for voting power.
-
This contract will set as owner of the Locker contract.
-
It will decide how many block's to wait to execute proposal.
- This contract will create the proposal and vote for the same.
- In this contact user can create the proposal, vote, cancel.
- There are several stages for proposal.
Sr No | Stages |
---|---|
0 |
Pending |
1 |
Active |
2 |
Cancelled |
3 |
Defeated |
4 |
Succeeded |
5 |
Queued |
6 |
Expired |
7 |
Executed |
- First of all we will deploy the contract. We will get contract address of all deploy contract.
npx hardhat run scripts/deploy.js --network ropsten
-
Nappy Token
:0xb1E2d34eE670F4B91C8015547D4E1F1f89a61f92
-
TimeLock
:0x8fC26556DfCD22cCEa0478feb67B29Aa0363D1B4
-
Governance
:0x032BA118F762c78dD254064F42C1B9dd9205731A
-
Locker
:0xF6BFeFAdD008FBF7F5F3b54E3ec5d1403967ac8f
-
After this we will call proposal contract.
npx hardhat run scripts/proposal.js --network ropsten
-
After this function we will get proposal Id.
-
Proposal Id
:6710164757546047754297806568396090581956979312861437213151479767075350705109
-
Now we will check state of the DAO.
-
Before check the state we have to wait for to mine 20 Blocks.
npx hardhat run scripts/state.js --network ropsten
-
It will give state
1
means our proposal isActive
. -
Now everyone will vote using castVote function.
npx hardhat run scripts/voting.js --network ropsten
- Now we will check state of the DAO.
npx hardhat run scripts/state.js --network ropsten
-
It will give state
4
means our proposal isSucceeded
. -
The voting is Succeeded.
-
Now we will call the
queue
function our proposal is pass.
npx hardhat run scripts/state.js --network ropsten
-
It will give state
5
means our proposal isQueued
. -
Now our proposal is in Queue.
-
Now we will Execute the proposal.
npx hardhat run scripts/execute.js --network ropsten
-
It will give state
7
means our proposal isExecuted
. -
Our proposal is successfully executed.
- This contract will store the ether. Anyone can send the ether to this contract.
- Only owner can withdraw the funds.
- It transfer ownership to
TimeLock
Contract usingtransferOwnership
function.
create .env file in root directory.
API_URL = "https://eth-ropsten.alchemyapi.io/v2/your-api-key"
PRIVATE_KEY = "YOUR-METAMASK-PRIVATE_KEY"
ETHERSCAN_API_KEY = "YOUR-ETHERSCAN_API_KEY"
-Get Your API Key
-Get Your Ropsten Faucet
Clone the project
git clone https://github.com/karangorania/dao-smart-contract
Go to the project directory
cd dao-smart-contract
Install dependencies
npm install
Compile
npx hardhat compile
Test
npx hardhat test
Deploy
node scripts/deploy.js
Deploy on Rinkeby
npx hardhat run scripts/deploy.js --network ropsten
Verify Contract
npx hardhat verify --network rinkeby <YOUR_CONTRACT_ADDRESS>
Help
npx hardhat help