0

我有两个要部署的智能合约。我想部署第一个,然后将第一个的地址传递给第二个的构造函数。我是 hardhat-deploy 的新手,并不断跟上这一点。

谢谢!

4

1 回答 1

1

首先创建文件“scripts/deploy.js”。

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

async function main() {
  const [deployer] = await ethers.getSigners();
  console.log('Deploying contracts with the account: ' + deployer.address);

  // Deploy First
    const First = await ethers.getContractFactory('FirstContract');
    const first = await First.deploy();

  // Deploy Second
    const Second = await ethers.getContractFactory('SecondContract');
    const second = await Second.deploy(first.address);

   console.log( "First: " + first.address );
   console.log( "Second: " + second.address ); 

}

main()
    .then(() => process.exit())
    .catch(error => {
        console.error(error);
        process.exit(1);
})

然后运行这个命令。

npx hardhat run scripts/deploy.js --network ropsten
于 2021-11-22T17:50:23.163 回答