Skip to content

Instantly share code, notes, and snippets.

@MayowaObisesan
Last active September 8, 2023 13:36
Show Gist options
  • Save MayowaObisesan/aadb9cc800d2ffad20ee3148154554e9 to your computer and use it in GitHub Desktop.
Save MayowaObisesan/aadb9cc800d2ffad20ee3148154554e9 to your computer and use it in GitHub Desktop.
This are the files needed to create and interact with a multisigFactory contract
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import {Transaction} from "../multisig.sol";
interface IMultisig {
function createTransaction(uint _amount, address _spender) external;
function getTransaction(uint id) external view returns (Transaction memory);
}
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import {MultiSig} from "./multisig.sol";
contract MultisigFactory {
MultiSig[] _multisig;
event Create(address _addr);
function getAllMultisig() external view returns (MultiSig[] memory) {
return _multisig;
}
function createMultisig(
address[] memory _admins
) external payable returns (MultiSig newMultisig) {
newMultisig = new MultiSig(_admins);
_multisig.push(newMultisig);
emit Create(address(newMultisig));
}
}
import { ethers } from "hardhat";
async function main() {
/**
* 1. ethers.deployContract()
* a. Helps you deploy your Contract.
* b. Takes in three arguments
* - The contract name (required)
* - The constructor arguments (optional)
* - The ether value (optional)
* c. The response from .deployContract() is passed to the `.waitForDeployment()` function
* 2. `.waitForDeployment()`
* a. A method called on the return value of the `.deployContract()`
* b. e.g.,
* const one = await ethers.deployContract("MyFirstContract", [1], {value: '10'})
* await one.waitForDeployment();
*/
const factory = await ethers.deployContract("MultisigFactory", []);
factory.waitForDeployment();
// console.log(factory);
// 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 // EOA
// 0x5FbDB2315678afecb367f032d93F642f64180aa3 // Deployed Contract Address
// 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 // EOA
// 0x5FbDB2315678afecb367f032d93F642f64180aa3 //
const [addr1, addr2, addr3] = await ethers.getSigners();
const admin = [addr1.address, addr2.address, addr3.address];
const childMultisig = await factory.createMultisig(admin);
// console.log(childMultisig);
// The event from the factory contract, used to get the address of the newly deployed contract (args)
// @ts-ignore
const childMultisigLogs = (await childMultisig.wait())?.logs[0]?.args[0];
console.log(childMultisigLogs);
// 0xa16E02E87b7454126E5E10d957A927A7F5B5d2be // Contract Instance address
const interactOnline = await ethers.getContractAt("IMultisig", childMultisigLogs);
// const onlineMoney = await interactOnline.createTransaction(ethers.parseEther("1000"), addr3.address);
// console.log(onlineMoney);
const ay = await interactOnline.getTransaction(1);
console.log(ay);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment