A fully functional Decentralized Autonomous Organization (DAO) built with Hardhat, Solidity, and OpenZeppelin contracts. This project demonstrates on-chain governance with proposal creation, voting, and execution mechanisms.
- ERC20 Governance Token with vote delegation and checkpointing
- TimeLock Controller for delayed execution of approved proposals
- Governor Contract for complete proposal lifecycle management
- Automated Scripts for proposal creation, voting, and execution
- Local Development with Hardhat network for testing
The DAO consists of four main contracts:
- GovernanceToken.sol - ERC20Votes token that grants voting power
- TimeLock.sol - TimelockController that enforces execution delays
- GovernorContract.sol - Main governance contract for proposals
- Box.sol - Example contract controlled by the DAO
- Node.js v16+
- Yarn or npm
- Basic understanding of Ethereum and Solidity
# Clone the repository
git clone https://github.com/sanskar717/DAO.git
cd DAO
# Install dependencies
yarn install# Start a local Hardhat node
yarn hardhat node
# In a new terminal, deploy contracts
yarn hardhat deploy --network localhostThe DAO workflow involves three main steps: Propose, Vote, and Execute.
yarn hardhat run scripts/propose.ts --network localhostThis creates a proposal to change a value in the Box contract. The proposal ID is saved to proposals.json.
yarn hardhat run scripts/vote.ts --network localhostCast your vote on the active proposal. Votes can be:
0= Against1= For2= Abstain
yarn hardhat run scripts/queue-and-execute.ts --network localhostAfter voting period ends, queue the proposal in the TimeLock, wait for the delay, then execute it.
DAO/
├── contracts/
│ ├── GovernanceToken.sol # ERC20Votes token
│ ├── TimeLock.sol # TimelockController
│ ├── GovernorContract.sol # Governor
│ └── Box.sol # Example governed contract
├── deploy/
│ ├── 01-deploy-governance-token.ts
│ ├── 02-deploy-time-lock.ts
│ ├── 03-deploy-governor-contract.ts
│ ├── 04-setup-governance-contract.ts
│ └── 05-deploy-box.ts
├── scripts/
│ ├── propose.ts # Create proposals
│ ├── vote.ts # Vote on proposals
│ └── queue-and-execute.ts # Queue and execute
├── utils/
│ ├── move-block.ts # Helper for local testing
│ └── move-time.ts # Helper for local testing
└── helper-hardhat-config.ts # Configuration constants
Key parameters can be modified in helper-hardhat-config.ts:
export const VOTING_DELAY = 1; // Blocks before voting starts
export const VOTING_PERIOD = 5; // Blocks for voting duration
export const MIN_DELAY = 3600; // Seconds before execution
export const QUORUM_PERCENTAGE = 4; // Minimum participation
export const NEW_STORE_VALUE = 77; // Example proposal value- Token Holders receive governance tokens and delegate voting power
- Proposers create proposals to execute actions
- Voters cast votes during the voting period
- TimeLock enforces a delay after proposal passes
- Executors can execute approved proposals after delay
Pending (0)- Waiting for voting delayActive (1)- Currently accepting votesCanceled (2)- Proposal was canceledDefeated (3)- Did not reach quorum or majoritySucceeded (4)- Passed and ready to queueQueued (5)- Queued in TimeLockExpired (6)- Execution window expiredExecuted (7)- Successfully executed
# Run tests (when implemented)
yarn hardhat test
# Check coverage
yarn hardhat coverage- Create a
.envfile:
SEPOLIA_RPC_URL=your_rpc_url
PRIVATE_KEY=your_private_key
ETHERSCAN_API_KEY=your_api_key- Deploy:
yarn hardhat deploy --network sepolia- Hardhat - Ethereum development environment
- Solidity ^0.8.25 - Smart contract language
- OpenZeppelin Contracts - Secure contract library
- TypeScript - Type-safe scripting
- Ethers.js v5 - Ethereum library
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome!
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Sanskar
- GitHub: @sanskar717
- OpenZeppelin for secure contract implementations
- Patrick Collins for Web3 education
- Hardhat team for excellent developer tools
⭐ Star this repo if you found it helpful!