We will be building a Solidity-based DAO Management Contract on SupraEVM, this guide walks you through the complete process of developing, deploying, and interacting with your contact on SupraEVM Network using Hardhat.
Prerequisites
Start building
1
Initiate a new hardhat project
mkdir SupDAO
cd SupDAO
npx hardhat init
This will initiate your hardhat project templates interface. We'll use the empty hardhat_config.js template and follow the Instructions to install the supporting node modules.
2
Configure the hardhat.config.js file by adding the SupraEVM network configuration:
Create an interactive script (scripts/interact.js) to perform all DAO functionalities.
const { ethers } = require("hardhat");
async function main() {
const daoAddress = " "; // Replace with your DAO contract address
const abi = [
// add your contract ABI once you deploy it on SupraEVM
];
const signer = await ethers.getSigner();
const daoContract = new ethers.Contract(daoAddress, abi, signer);
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
async function menu() {
console.log("\nWelcome to the DAO Interaction Script!");
console.log("Choose an action:");
console.log("1. Add a DAO Member");
console.log("2. Create a Proposal");
console.log("3. Vote on a Proposal");
console.log("4. Execute a Proposal");
console.log("5. Exit");
readline.question("Enter the number of the action: ", async (action) => {
try {
if (action === "1") {
readline.question("Enter the member's address: ", async (address) => {
const tx = await daoContract.addMember(address);
await tx.wait();
console.log(`Address ${address} added as a DAO member!`);
await menu(); // Loop back to menu
});
} else if (action === "2") {
readline.question("Enter the proposal description: ", async (description) => {
const tx = await daoContract.createProposal(description);
await tx.wait();
console.log("Proposal created successfully!");
await menu(); // Loop back to menu
});
} else if (action === "3") {
readline.question("Enter the proposal ID to vote on: ", async (proposalId) => {
const tx = await daoContract.vote(proposalId);
await tx.wait();
console.log(`Vote cast for proposal ID ${proposalId}!`);
await menu(); // Loop back to menu
});
} else if (action === "4") {
readline.question("Enter the proposal ID to execute: ", async (proposalId) => {
const tx = await daoContract.executeProposal(proposalId);
await tx.wait();
console.log(`Proposal ID ${proposalId} executed successfully!`);
await menu(); // Loop back to menu
});
} else if (action === "5") {
console.log("Exiting. Goodbye!");
readline.close();
} else {
console.log("Invalid action. Please try again.");
await menu(); // Loop back to menu
}
} catch (error) {
console.error("An error occurred:", error.message);
await menu(); // Loop back to menu
}
});
}
await menu(); // Start the menu loop
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
8
Interacting with the contract
Run the interactive script scripts/interact.js in your terminal.
npx hardhat run scripts/interact.js --network supra
Github repository for the contract breakdown and source code: