Member-only story
How to Code an On-Chain DAO
Build a decentralized governance model from scratch with hardhat, TypeScript, solidity, and Openzeppelin. This DAO (Decentralized Autonomous Organization) uses an ERC20 token with voting power to make decisions

Introduction
We are going to learn how to build an on-chain DAO using hardhat, solidity, typescript, and Openzeppelin. For those of you who don’t know, a DAO is a decentralized autonomous organization that is typically powered by the blockchain. You can watch my previous video overview about the DAO tooling landscape or read my previous article on How to build a DAO (High Level).
For this one, we are jumping right into the code. We will be using a 100% on-chain governance model, using an ERC20 token to vote for proposed changes. Once tooling improves for off-chain voting (using the Chainlink OCR model and a decentralized database like IPFS), we’ll probably have a tutorial to do that to save gas.
But to reiterate, be 100% sure to read my previous article on the landscape of the space before following here! Additionally, if you want to see a pythonic version with brownie, you can watch the video here, and see the code here.
Hardhat Video:
Quickstart
The quickest way to get everything is to just do the following:
git clone https://github.com/PatrickAlphaC/dao-template
cd dao-template
yarn
yarn hardhat test
And boom! You’ll run through the tests that mock proposing a vote, voting on a vote, queueing the vote, then executing!
Here is the rundown of what the test suite does:
- We deploy an ERC20 token that we will use to govern our DAO.
- We deploy a Timelock contract that we will use to give a buffer between executing proposals.
Note: The timelock is the…