MATeS of Moonbeam
Published in

MATeS of Moonbeam

Build your First DAO and deploy it to moonbeam network PART1 : Setup and play around

The acronym DAO stands for Decentralized Autonomous Organization. In general, a DAO is a system of hard-coded rules that define which actions a decentralized organization will take.

This sentence is my favorite short explanation of DAO, I borrowed it from binance academy, you can check more detail here .

DAO is not the new concept, it was introduced to everyone since the first age of Defi, It’s treated as a backbone of many DEFI organization, that allows customers to involve and set the direction with core team by vote system. it’s fully decentralized and transparent.

Let’s Build !!

Talk is cheap, it’s time to take some action. The great way to understand what really DAO is, It’s to build it one, let’s build it!

First, we assumed that you have some knowledge about solidity development, if you’re not familiar with it, please check this link first.

Learn from the existed contract

The best way to learn how to build some smart contracts is just to learn from an existing and famous smart contract. As you already know, Smart contract is open for everyone to check the code and learn from it. so, in this tutorial, I’ve selected this repo to be our guideline. This project based on scaffold-eth, which is the web3 boilerplate and best resource to start some web3 app. This boilerplate included all development workflow with very well commented on each line, to help you understand more in detail. For more detail about this boilerplate, please check here.

Design the features

Before we deep dive into the smart contract coding, we have to design the features first. So what are the functionalities that a particular DAO need?

Add and Remove Member

Yeah, this one is very basic functionality that every DAO should have, DAO has to be able to add a new member and revoke some member.

create some proposal and revoke

The proposal is also the main functionality here, everyone should be able to send some proposal with the detail, and the proposal’s issuer doesn’t need to be DAO’s member to propose something.

DAO member can vote proposal

This should also be a main functionality, that DAO member should be able to vote or reject proposals created by everyone, but only DAO member who be able to vote to accept or reject the proposal.

Create Proposal to add or kick some member

Member management is also an important one. DAO is decentralized by design, so it shouldn’t have someone who have authority over others, every organization's decision is made by vote, so it is the same for this feature. DAO member should be able to create an issue to add or revoke some member, and let others member vote to execute.

payout and withdrawal

After the proposal has been accepted by DAO members, issuer should be able to make withdrawal transaction to specific issuer address. and for transparency, DAO member should be able to check all history of payout in order to manage the organization's financial.

Getting start !!

First of all, we have clone repo and check the project’s structure first.

git clone simpleDAO

Once it finished, cd simpleDAO , you should see the project structure like this

- hardhat
- react-app
- services
- subgraph
...others config files

This boilerplate use monorepo to manage all dependencies version. let’s check the package one by one.


This package included all smart contract code and also smart contract development config. We use hardhat the web3 development framework to help us prepare a development environment for developing the app. Hardhat could provide you blockchain node simulator, solidity compiler, and deployment script.


This is the frontend part, it’s a react app that already have web3 connection functionality, as we won’t focus much on frontend develop on this tutorial. We just focus on web3 connection part on frontend, if you not familiar with react much, don’t worry.


All dockers config & script for spinoff some web3 service, graph node, arbitrum etc. we don’t use any service here on this tutorial.


All subgraph related config, subgraph could help you to store specific blockchain data for general purpose usage on you app. Anyway, we don’t use any subgraph on this tutorial.

Setup development environment

As we have already talking about, Hardhat could help us setup development environment on the machine so let try it. First, install all reps first.

yarn install

Then, you trying to run blockchain node on your local.

yarn chain

The boilerplate already prepared hardhat config and script for you, by running this command, it will start ETH node on your local machine.

yarn run v1.22.10
$ yarn workspace @scaffold-eth/hardhat chain
$ hardhat node --network hardhat --no-deploy
Started HTTP and WebSocket JSON-RPC server at
eth_blockNumber (3)

You will notice, that there’s some activity here, it keeps printing out some log on the terminal. It’s the mining process that hardhat simulate block mining on blockchain, it will generate the new block around 3–4 sec/block (based on boilerplate setup), when the new block generated it will printout eth_blockNumber (X) (X = block number).

Next step, we will try to deploy the smart contract, and check how hardhat deployment work. So just run this command first

yarn deploy

This command also is prepared by boilerplate, after you run, you should see the result log like.

$ yarn workspace @scaffold-eth/hardhat deploy
$ hardhat deploy --export-all ../react-app/src/contracts/hardhat_contracts.json
Nothing to compile
deploying "PowDAO" (tx: 0xa3065dc6a9f19da468e99c3ecc58d42ae16299a152bb9eb52929fcadc7340be7)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2068758 gas
$ hardhat run scripts/publish.js
✅ Published contracts to the subgraph package.
✨ Done in 3.90s.

It printout result in your smart contract’s address and also deployment transaction and gas consumed to help you estimate deployment gas used.

Let deep dive a bit on how the deployment process work

Let’s check on package.json file,

"scripts": {
"chain": "hardhat node --network hardhat --no-deploy",
"deploy": "hardhat deploy --export-all ../react-app/src/contracts/hardhat_contracts.json",

Yarn deploy is just an alias of hardhat deploy , this process will deploy smart contract with attribute that define on packages/hardhat/deploy/00_deploy_your_contract.js and export result as and json abi of contract to react-app frontend package, then our frontend can call abi directly with reference from this generated file.

Let’s check more detail on deployment script

// packages/hardhat/deploy/00_deploy_your_contract.jsmodule.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const members = [
]; // browser burner wallet and powvt.eth addresses.
PowDAO = await deploy("PowDAO", {
// Learn more about args here:
from: deployer,
args: [members],
log: true,
module.exports.tags = ["<your-contract-name>"];

This function will be called by hardhat deployment mechanism, that send deployments variable on the argument, so we can use deploy function to deploy smart contract with initial parameter which will be parameter of smart contract contractor (will elaborate more detail later). This smart contract initial parameter is array of initial member address, this addresses will be the first member of DAO, who have authority to invite others into the DAO by voting mechanism.

After your first contract is deployed, we’re ready now to try out something on Frontend, let's run frontend

yarn start

waiting a min, It will automatically show react application, then you should see the template UI from boilerplate.

Let’s play around

Let's play boilerplate to get more understanding of DAO functionality first. before trying any feature, please make sure that you’re currently selecting the same address that you provided on deployment file above, if not you’ll not be available to use any feature here.

You can simply check your member status on DAO by pasting your address here, if you’re DAO member it’ll show the result like this.

Let try other functionality, the first feature that your DAO should have is add/remove member, it’s entrance to add other member into your DAO. let's try by adding other address, then click “Add” (please make sure, you’re currently logged in with the authorized address one before take action)

As we already talking about previously, every action on DAO need voting mechanism, so after you confirm the transaction, the new vote will be created on the list below.

Then, click on vote “Yes”, then confirm the vote will already submitted. Then we have to wait until the voting period is ended, the voting period is configured as 1 min by default on boilerplate.

After 1 minute, try to execute the proposal here, by typing the proposal id, which is ‘0’ then clicking process, the proposal will check the voting consensus and execute the action. so right now, we have 1 “Yes” vote and 0 “No”, so the consensus is “Yes”. After execution let check member by placing an address on the proposal, now the new member has been added. 🎉

Next, we’ll try another main feature, Create proposal for fund, Let’s go !

Add some detail about your proposal on first input, and add the money you need to request. As I already explained previously, anyone could create this proposal. To prove this functionality, I’ll switch to another address that not DAO’s member first.

Great !!, the proposal is already submitted from non-member address. Let’s approve it, switch back to DAO’s member wallet, then repeat the same step as we do with add member proposal.

Oh !, it shows some error when trying to execute the proposal. the boilerplate didn’t show all errors yet, so you need to check on your terminal that your EVM is running (the terminal window that you run yarn chain).

Error: VM Exception while processing transaction: reverted with reason string 'DAO balance too low to accept the proposal.'

Hmm, What does it mean ??? 🤨
yeah it means your contract doesn’t have any balance to give anyone 🤣. Let's put some money into the DAO first. fortunately, we playing on localhost, so could faucet any balance to any wallet address, we’re a god 🧖

Let find contract address first, click on contact tab above, this page is like dev console UI for debugging and execute smart contract directly, then click on copy icon. It’ll be copied to your clipboard.

Then click wallet icon on bottom left, we gonna use god power to faucet some money to DAO contract.

Place you address on the first field , and add number of balance you needed. Then “send”., you contract will show balance that you send to.

Next, trying to create the new proposal, then vote “yes” and try to execute the proposal again. It should be successfully this time

Let's check balance payout we got from the proposal, switch back to wallet address that submitted the proposal, and click “check payout” to check. Then click “Get Paid”, Hooray !! 🎉 now you got the money now from DAO.

Now we already tried all the main functionality of DAO and that’s so awesome. unfortunately, this article is too long, so I have to cut it off first.

In the next part, we will take a look deeply at smart contact code for all functionality that we have tried in this article.

see you in the next article, and many thanks for your interest. 😃




Decentralized and permissionless, Moonbeam provides an Ethereum-compatible smart contract platform that makes it easy to build natively interoperable applications. Powered by the Polkadot network.

Recommended from Medium

KeenTools 2022.1: Blender 3.1 and Apple Silicon support, facial expression extraction

Build Your Text Editor With Rust! Part 3

ow to install SDKMAN on Windows 10

VMware Joins Docker Verified Publisher Program

Top 5 reasons to avoid no-code solutions

Is JAVASCRIPT your cup of tea?

Display GKE logs in a text format with kubectl

MySQL Database Indexing for Developers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Web3 Creator, Lifelong Learner, entrepreneur

More from Medium

PNX — 067 | Daily NFT News

Allowlist System

Web3 Education Meets Adorable Ghosts

How to build NFTs using Solana blockchain