const { ethers } = require('hardhat'); const fs = require('fs'); const contractAddresses = require('../contract-addresses.json'); const network = process.env.HARDHAT_NETWORK; async function main() { const dao = await ethers.deployContract('DAO'); await dao.waitForDeployment(); console.log(`DAO deployed to ${dao.target}`); contractAddresses[network].DAO = dao.target; fs.copyFileSync('./artifacts/contracts/DAO.sol/DAO.json', '../client/src/assets/DAO.json'); const deployWorkContract = async (name, price) => { const contract = await ethers.deployContract('Work1', [dao.target, price]); await contract.waitForDeployment(); console.log(`${name} deployed to ${contract.target}`); contractAddresses[network][name] = contract.target; fs.copyFileSync(`./artifacts/contracts/${name}.sol/${name}.json`, `../client/src/assets/${name}.json`); }; await deployWorkContract('Work1', ethers.parseEther('0.001')); await deployWorkContract('Onboarding', ethers.parseEther('0.001')); fs.writeFileSync('../client/src/contract-addresses.json', JSON.stringify(contractAddresses, null, 2)); console.log('Wrote file', fs.realpathSync('../client/src/contract-addresses.json')); fs.writeFileSync('./contract-addresses.json', JSON.stringify(contractAddresses, null, 2)); console.log('Wrote file', fs.realpathSync('./contract-addresses.json')); console.log('Copied ABIs to', fs.realpathSync('../client/src/assets')); } // We recommend this pattern to be able to use async/await everywhere // and properly handle errors. main().catch((error) => { console.error(error); process.exitCode = 1; });