首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用hardhat-deploy部署多个智能合约

如何使用hardhat-deploy部署多个智能合约
EN

Stack Overflow用户
提问于 2021-11-02 14:54:28
回答 1查看 628关注 0票数 0

我有两个要部署的智能合约。我想部署第一个函数,然后将第一个函数的地址传递给第二个函数的构造函数。我是个刚开始使用硬件部署的人,并且一直都在关注这个问题。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-11-22 17:50:23

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

代码语言:javascript
运行
复制
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);
})

然后运行此命令。

代码语言:javascript
运行
复制
npx hardhat run scripts/deploy.js --network ropsten
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69812460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档