This tutorial will show you to create a DAOhaus Boost that interacts with a Smart Contract
Creating a DAOhaus Boost is a way to add functionality to the DAOhaus Interface. This tutorial will show you how to create a Contract Boost.
Contract Boosts enable your DAO to initiate an interaction with an external contract. See the DAOhaus Proposal Process for more information about how proposals work in the DAOhaus app.
This "Mint a Million" Contract Boost will allow a DAO to create an ERC-20 token with 1 million supply using a Factory Contract we have supplied for you. The token will be managed by a Minion and Safe in your DAO.
Learn more about Minions & Safes
To build a Contract Boost, there are 3 primary components you'll need to create:
For more information on how Boosts work, refer to the Overview page here
Resources:
Before you begin,
mint_a_million_<yourdiscordhandle>
. Your discord handle in the branch name helps us when providing support.
git clone https://github.com/HausDAO/daohaus-app.git
cd daohaus-app
git branch mint_a_million_yourhandle
git checkout mint_a_million_yourhandle
touch .env
.env
file you just created in your root directory and add the following:GENERATE_SOURCEMAP=false
REACT_APP_DEV=true
Do we need the Infura Project ID, RPC URI?
What does generate_sourcemap do?
From the root of your application:
yarn install
to install dependenciesyarn start
to launch the DAOhaus appFor guidelines on contributing to DAOhaus repositories, refer to the Contributing Guidelines here
In this step, we will set up your Contract Boost's proposal form and fields that are required to create the proposal and execute the external contract call.
As it stands, these tutorial branches can't be merged because there would be filename collisions
Question: Actually following this tutorial will lead to duplicate files if pushed and merged. Maybe we want to modify this to add their boost to a "Tutorial Playlist" that automatically creates a token of their choosing… some modification could end up with a long list of slightly different summon token boosts, which would be pretty cool
src/data/formLegos/
for your BoostThis file will export a single javascript object that the DAOhaus App will use to generate the form for your boost.
Though it is possible to specify multiple forms in one file, in this case there is just one form called SUMMON_TOKEN
Add the following code to mintAMillionForms.js:
import { MINION_TYPES, PROPOSAL_TYPES } from '../../utils/proposalUtils';
import { FIELD } from '../fields';
import { TX } from '../txLegos/contractTX';
export const MILLION_FORMS = {
SUMMON_TOKEN: {
id: 'SUMMON_TOKEN',
title: 'Mint A Million',
description: 'Mint a million of a new token!',
type: PROPOSAL_TYPES.MINT_A_MILLION, // Custom proposal types that allow you to render custom proposal UIs ??
minionType: MINION_TYPES.SAFE, // Selects only the "Safe Minion"
dev: true, // Shows the Proposal on your DEV Test List for testing
logValues: true, // Logs form values in the console
tx: null, // Will build this in step 2
required: [], // Specifies required fields from the below fields
fields: [], // Specifies fields to be shown on the form
},
};
The dev: true
will let you see your form in the 'DEV Test List' playlist - a special playlist used for testing. It will be visible only because you added REACT_APP_DEV=true to your .env file above.
Playlists are groupings of proposals that are related to one another. For instance, the DEV Test List playlist will display all the proposal types in the development environment.
This allows you to access and test the proposal before it is complete.
To preview your Proposal Playlist, you will need to have an existing DAO locally. If you have not already summoned a DAO, you can summon one at localhost:3000/summon
First, yarn start
and Load the app at http://localhost:3000.
Navigate to your DAO and click on New Proposal. Select Manage on the Proposal Playlist modal.
You should be able to see a Playlist called "DEV Test List" with the "Mint a Million" Proposal type. (51:32)
src/utils/proposalUtils.jsx
Add MINT_A_MILLION: 'Mint a Million',
to the PROPOSAL_TYPES
object in src/utils/proposalUtils.jsx
(see line 66).
proposalsUtils.js
is the central directory for all proposal utilities available in the DAOhaus app. This step signals to the DAOhaus App that it should consider your boost proposal as a valid proposal type.
Are we sure this needs to come before the form is made?
...
export const PROPOSAL_TYPES = {
CORE: 'Core',
MEMBER: 'Member Proposal',
SIGNAL: 'Signal Proposal',
...
SWAPR_STAKING: 'Swapr Staking Proposal',
POSTER_RATIFY: 'Ratify Content',
POSTER_RATIFY_DOC: 'Ratify DAO DOC',
MINT_A_MILLION: 'Mint a Million',
};
...
When creating the form, we need to create fields to collect data from users that will be used to initiate the contract call.
In this form, we will include:
Select a Minion
field for DAO members to indicate the address that owns the newly minted ERC-20 tokensToken Name
field for the token's name (e.g My Cool Token
)Token Symbol
field for the token's symbol (e.g. MCT
)FIELD.MINION.SELECT
as the first field (49:58)In mintAMillionForms.js
add a minion select field to your fields array:
...
fields: [
// Specifies fields to be shown on the form
[FIELD.MINION_SELECT],
],
...
FIELD.MINION_SELECT
is a prebuilt form field that provides a dropdown with all of your DAO's minions. This field will give us access to the Safe Minion address, which we will need to construct our transaction in Step 3.
Modify mintAMillionForms.js
to add these custom fields to your fields array:
...
fields: [
[
// Specifies fields to be shown on the form
[FIELD.MINION_SELECT],
],
[
{
type: 'input', // Standard HTML input
label: 'Token Name', // Renders this as form title
name: 'tokenName', // This is how the field will be referenced across files
htmlFor: 'tokenName',
placeholder: 'Token Name', // Placeholder text
expectType: 'any', // Type check (e.g. 'number')
},
{
type: 'input',
label: 'Token Symbol',
name: 'tokenSymbol',
htmlFor: 'tokenSymbol',
placeholder: 'Token Symbol',
expectType: 'any',
},
],
],
...
While there are many field types within the DAOhaus App that can be reused in your form, in this case will make custom form fields to collect the token name and the token symbol.
A Note on Form Columns: Note that the fields
array includes a subarray, which holds the form fields. If you would like to create a form with multiple columns, include multiple subarrays, one for each column, within the fields
array. Form elements that you put in these separate subarrays will appear in seaprate columns.
For more information on Form Legos, refer to Form Legos
TODO ask Jord what htmlFor does in code snippet above
For this form, we need DAO members to fill in all three fields (i.e. Select a Minion, Token Name & Token Symbol).
Add the name
property of each field into the required
array. If the user does not provide these fields, the form will not be submitted.
Your completed mintAMillionForms.js
file should look like this.
import { MINION_TYPES, PROPOSAL_TYPES } from '../../utils/proposalUtils';
import { FIELD } from '../fields';
import { TX } from '../txLegos/contractTX';
export const MILLION_FORMS = {
SUMMON_TOKEN: {
id: 'SUMMON_TOKEN',
title: 'Mint A Million',
description: 'Mint a million of a new token!',
type: PROPOSAL_TYPES.MINT_A_MILLION,
minionType: MINION_TYPES.SAFE,
dev: true,
logValues: true,
tx: TX.SUMMON_TOKEN,
required: ['tokenName', 'tokenSymbol', 'selectedMinion'],
fields: [
[
FIELD.MINION_SELECT,
{
type: 'input',
label: 'Token Name',
name: 'tokenName',
htmlFor: 'tokenName',
placeholder: 'Token name',
expectType: 'any',
},
{
type: 'input',
label: 'Token Symbol',
name: 'tokenSymbol',
htmlFor: 'tokenSymbol',
placeholder: 'Token Symbol',
expectType: 'any',
},
],
],
},
};
MILLION_FORMS
object to src/data/formLegos/forms.js
First, import the MILLION_FORMS
object in forms.js
.
Add import { MILLION_FORMS } from './mintAMillionForms';
to the list of imports
Next add ...MILLION_FORMS
to the FORM
object.
forms.js
is the central directory for all forms available in the DAOhaus app. This step imports and stores the MILLION_FORMS
object (i.e. Mint a Million form formats) in the central directory.
import { CLASSIC_FORMS } from './classics';
...
import { POSTER_FORMS } from './posterForms';
import { MILLION_FORMS } from './mintAMillionForms'; //ADD THIS
export const FORM = {
...CLASSIC_FORMS,
...
...POSTER_FORMS,
...MILLION_FORMS, //AND THIS
};
Now that you have created your form and added it to the DAOhaus App, you can preview it in the DEV Test List
playlist.
To preview the form in your development environment, navigate to the DEV Test List
by clicking on Proposals > New Proposal > Manage(Gear Icon) > DEV Test List.
Again, you will need to have an existing DAO to preview your Proposal Playlist. If you have not already summoned a DAO, you can summon one at localhost:3000/summon
We went into this earlier, but maybe we don't say anything until now when they can see it
The test "Mint a Million" proposal is now visible in the Dev Test List
(51:32) because we set these properties:
dev: true
(in mintAMillionForms.js
)REACT_APP_DEV=true
(in .env
)http://localhost:3000/dao/0x4/0xba91c92c3fcd67b8e29596cb2a49f418f7715142/settings/proposals
Now that your proposal form is ready, let's set up the contracts that your Boost will be interacting with.
src/utils/chain.js
The chain.js
file stores all the contract addresses that the application needs to have access to. Contract addresses are separated by network chains (e.g. Ethereum Mainnet, Rinkeby, etc.)
Our contract exists on Rinkeby, so we will add the contract address to the Rinkeby object. The Mint a Million Contract address is 0xe4E893AffD33dDED43ECdf8bBC550639c84485e5
Add erc20_summon:'0xe4E893AffD33dDED43ECdf8bBC550639c84485e5',
to the '0x4'
(i.e. Rinkeby) object. Your field can technically be added anywhere in the object, but let's add it after the moloch_factor_addr
in chain.js
field to keep things organized:
'0x4': {
name: 'Ethereum Rinkeby',
short_name: 'rinkeby',
shortNamePrefix: 'rin',
nativeCurrency: 'ETH',
network: 'rinkeby',
network_id: 4,
chain_id: '0x4',
...
minion_factory_addr: '0x313F02A44089150C9ff7011D4e87b52404A914A9',
moloch_factory_addr: '0xC33a4EfecB11D2cAD8E7d8d2a6b5E7FEacCC521d',
erc20_summon: '0xe4E893AffD33dDED43ECdf8bBC550639c84485e5', // Our contract address
...
}
src/data/contracts.js
Open src/data/contract.js
and add the following ERC_20_SUMMON
object to the CONTRACTS object:
export const CONTRACTS = {
...
ERC_20_SUMMON: {
location: 'local',
abiName: 'ERC_20_SUMMON',
contractAddress: '.contextData.chainConfig.erc20_summon',
},
...
}
The DAOhaus application uses a .
search notation to point to data / properties within objects in the codebase. For instance, the contractAddress: '.contextData.chainConfig.erc20_summon',
will point to the erc20_summon
property within the chainConfig
object that you added in Step 2.1 above
src/contracts
called erc20Summon.json (1:07:33)erc20Summon.json
First, navigate to the Mint a Million contract on Etherscan.
Next, copy and paste the ABIs for this contract by clicking the 'Copy All to clipboard' button in the Contract ABI section.
Paste the Contract ABI into erc20Summon.json
These ABIs will be used by the DAOhaus app when creating a transaction and interacting with the smart contract's available functions.
src/utils/abi.js
(1:08:10)The abi.json
file is a central directory of all contract ABIs which the DAOhaus app will interact with. This step imports and stores the ERC_20_SUMMON
object (i.e. Mint a Million Factory contract ABIs) into the central directory.
Open src/utils/abi.js
and add the following 2 lines:
import ERC_20_SUMMON from '../contracts/erc20Summon.json'
ERC_20_SUMMON,
The resulting file should look something like this:
import { encodeMultiSend } from '@gnosis.pm/safe-contracts';
import Web3 from 'web3';
import { Contract, BigNumber } from 'ethers';
...
import MOLOCH_TOKEN_FACTORY from '../contracts/molochTokenFactory.json';
import ERC_20_SUMMON from '../contracts/erc20Summon.json' // ADD THIS
...
export const LOCAL_ABI = Object.freeze({
MOLOCH_V2,
ERC_20,
VANILLA_MINION,
...
MOLOCH_TOKEN_FACTORY,
ERC_20_SUMMON, // AND THIS
...
Verify that the ERC_20_SUMMON
property matches in both src/utils/abi.js
and src/data/contracts.js
src/data/details.js
Add the following code to the DETAILS
object
MILLION: {
title: `Mint a Million!!!`,
proposalType: '.formData.type',
},
The title
object will determine the Proposal title on the Proposal Card within the DAOhaus app.
The proposalType
object will reference the proposal type, which appears in different places in the DAOhaus UI. .formData.type
references the fields you added to src/utils/proposalUtils.jsx
earlier in the tutorial.
At the end of this step, you have done the necessary set up for your contracts within the DAOhaus app. The next step will be to build and test your transaction!
millionTx.js
in src/data/txLegos
(1:11:45)First, create a new file called millionTx.js
in src/data/txLegos
Next, add the following code into the MILLION_TX
object.
Is it the case that this matches the SUMMON_TOKEN we put in the form above? These details will be important when people want to make their own custom boost
import { buildMultiTxAction } from '../../utils/legos';
import { CONTRACTS } from '../contracts';
export const MILLION_TX = {
SUMMON_TOKEN: buildMultiTxAction({ // TODO
actions: [
{
targetContract: '.contextData.chainConfig.erc20_summon', // Location for Contract Address (Added in the previous step)
abi: CONTRACTS.ERC_20_SUMMON, // Contract ABI (Added in the previous step)
fnName: 'summonToken', // Function name in ABI
args: [],
},
],
}),
};
Recall that we pasted these fields into the erc20Summon.json
file after copying them from the Contract ABI section on Etherscan:
"inputs": [
{ "internalType": "uint256", "name": "supply", "type": "uint256" },
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "string", "name": "symbol", "type": "string" },
{ "internalType": "address", "name": "receiver", "type": "address" }
In our new file millionTx.js
we need to specify the arguments for the transaction in the same order as they are defined by the Contract ABI.
Add the following arguments to the args
property in millionTx.js
:
args: [
'1000000000000000000000000', // Supply (Hardcoded to 1 million in Gwei)
'.values.tokenName', // Token Name
'.values.tokenSymbol', // Token Symbol
'.values.selectedSafeAddress', // Safe Address as the owner
],
The DAOhaus app uses React Hooks in its forms, which returns form inputs in an object called values
. In the above example we specified a hardcoded value of 1000000000000000000000000 for the first property.
For the next 3 properties we used dot notation to extract the values provided by the users of the form. In this way we can collect the Token Name, Token Symbol and Selected Safe Address respectively.
Selected Safe Address is made available by the MINION_SELECT form field we specified in step 1.3.1
When building the transaction, the above values will be submitted as a part of the transaction. This will mint 1,000,000 tokens with name and symbol specified by the user, specificing the Minion Safe as the owner.
detailstoJSON
referenceImport the DETAILS
object into millionTX.js
:
import { DETAILS } from '../details';
Add the following property to the SUMMON_TOKEN
object:
detailstoJSON: DETAILS.MILLION,
The detailstoJSON property refers to the JSON object added to details.js
(Step 2.6) which contains all proposal details required for rendering proposals (e.g. title, description, etc.)
At the end of this step, your code in millionTX.js
should look like this
import { buildMultiTxAction } from '../../utils/legos';
import { CONTRACTS } from '../contracts';
import { DETAILS } from '../details';
export const MILLION_TX = {
SUMMON_TOKEN: buildMultiTxAction({
actions: [
{
targetContract: '.contextData.chainConfig.erc20_summon',
abi: CONTRACTS.ERC_20_SUMMON,
fnName: 'summonToken',
args: [
'1000000000000000000000000',
'.values.tokenName',
'.values.tokenSymbol',
'.values.selectedSafeAddress',
],
},
],
detailsToJSON: DETAILS.MILLION,
}),
};
src/txLegos/contractTX.js
First, add the following code to import the MILLION_TX
object.
import { MILLION_TX } from './millionTX';
Next, add
...MILLION_TX,
to the TX
object in src/txLegos/contractTX.js
.
Once this step is complete, you are ready to test your transaction to mint a million tokens.
Navigate to your Proposals and submit a Mint a Million Proposal to test your Boost!
Have them submit a PR? We won't be able to merge them but we could have a list of tutorial PRs that people have made.
Checklist for submitting a boost:
how many transactions and forms
How do you want to package this
Do you want it all in one group/playlist