Start Building

Initialize a new Hardhat project and prepare it for deployment on SupraEVM.


1

Step 1: Initialize Your Project

Set up your folder, initialize Hardhat, and prepare your config file.

mkdir SupDAO
cd SupDAO
npx hardhat init

Choose the empty hardhat.config.js template and install any required node modules.

2

Step 2: Configure Hardhat for SupraEVM

Update your hardhat.config.js file with the SupraEVM network:

For the latest RPC URL, please refer to the Supra Network Information page.

module.exports = {
    solidity: "0.8.17",
    networks: {
        supra: {
            url: "SUPRAEVM_RPC_URL",
            accounts: ["YOUR_STARKEY_WALLET_PRIVATE_KEY"]
        }
    }
};
3

Step 3: Create Your DAO Contract

Inside a new contracts/ directory, create your Solidity file (e.g., CrossChainDAO.sol):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract CrossChainDAO {
    struct Proposal {
        uint id;
        string description;
        uint voteCount;
        bool executed;
    }

    address public owner;
    uint public proposalCount;
    mapping(uint => Proposal) public proposals;
    mapping(address => bool) public members;

    event ProposalCreated(uint id, string description);
    event VoteCasted(uint id, address voter);
    event ProposalExecuted(uint id);

    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner can call this function");
        _;
    }

    modifier onlyMember() {
        require(members[msg.sender], "Only DAO members can vote");
        _;
    }

    constructor() {
        owner = msg.sender;
    }

    function addMember(address _member) external onlyOwner {
        members[_member] = true;
    }

    function createProposal(string memory _description) external onlyMember {
        proposalCount++;
        proposals[proposalCount] = Proposal(proposalCount, _description, 0, false);
        emit ProposalCreated(proposalCount, _description);
    }

    function vote(uint _id) external onlyMember {
        Proposal storage proposal = proposals[_id];
        require(!proposal.executed, "Proposal already executed");
        proposal.voteCount++;
        emit VoteCasted(_id, msg.sender);
    }

    function executeProposal(uint _id) external onlyOwner {
        Proposal storage proposal = proposals[_id];
        require(!proposal.executed, "Proposal already executed");
        require(proposal.voteCount > 0, "Insufficient votes to execute the proposal");
        proposal.executed = true;
        emit ProposalExecuted(_id);
    }
}
4

Step 4: Compile Your Contract

Make sure the Solidity code builds successfully.

npx hardhat compile
5

Step 5: Create a Deployment Script

Add a scripts/deploy.js file to deploy your DAO contract to SupraEVM.

const { ethers } = require("hardhat");

async function main() {
    const CrossChainDAO = await ethers.getContractFactory("CrossChainDAO");
    const dao = await CrossChainDAO.deploy();
    await dao.deployed();
    console.log("DAO deployed to:", dao.address);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});
6

Step 6: Deploy to SupraEVM

Run your deploy script on the SupraEVM network.

npx hardhat run scripts/deploy.js --network supra
7

Step 7: Create Interaction Script

Add a menu-based script that interacts with your deployed DAO.

const { ethers } = require("hardhat");

async function main() {
    const daoAddress = ""; // Replace with your deployed DAO contract address
    const abi = []; // Add ABI after deployment
    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("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 your choice: ", async (action) => {
            try {
                if (action === "1") {
                    readline.question("Member address: ", async (address) => {
                        const tx = await daoContract.addMember(address);
                        await tx.wait();
                        console.log(`Member added: ${address}`);
                        await menu();
                    });
                } else if (action === "2") {
                    readline.question("Proposal description: ", async (description) => {
                        const tx = await daoContract.createProposal(description);
                        await tx.wait();
                        console.log("Proposal created!");
                        await menu();
                    });
                } else if (action === "3") {
                    readline.question("Proposal ID: ", async (id) => {
                        const tx = await daoContract.vote(id);
                        await tx.wait();
                        console.log(`Voted on proposal ${id}`);
                        await menu();
                    });
                } else if (action === "4") {
                    readline.question("Proposal ID: ", async (id) => {
                        const tx = await daoContract.executeProposal(id);
                        await tx.wait();
                        console.log(`Executed proposal ${id}`);
                        await menu();
                    });
                } else if (action === "5") {
                    console.log("Exiting...");
                    readline.close();
                } else {
                    console.log("Invalid choice.");
                    await menu();
                }
            } catch (err) {
                console.error("Error:", err.message);
                await menu();
            }
        });
    }

    await menu();
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});
8

Step 8: Run the Interaction Script

Run your interaction script:

npx hardhat run scripts/interact.js --network supra

Last updated