使用多个钱包的Hardhat智能合约部署脚本

huangapple go评论56阅读模式
英文:

Hardhat smart contract deployment script using multiple wallets

问题

在hardhat配置文件中,我可以通过在账户字段中使用数组来提供多个钱包。如何访问第二个签署者?我想要创建一个单一运行的部署脚本,以使用不同的签署者部署两个合同。

我知道我可以将部署分为两部分,每个部分都有自己的配置,但我的用例是一个包含12个合同的代码库,它们之间有复杂的依赖关系,我希望一次性部署它们。

我正在使用以下方法进行部署:https://hardhat.org/hardhat-runner/docs/guides/deploying

如果有类似的第二个签署者示例将非常有帮助。

英文:

In hardhat config file I am able to provide multiple wallets via an array in the account field. How do I access the 2nd signer? I would like to have a single run deploy script to deploy two contracts each with a different signer.

I know I can just split the deployment into two each with their own config, but my use case is a 12 contract codebase with intricate dependencies between them and I'd like to deploy all of them in one go.

I'm using this approach to deploy: https://hardhat.org/hardhat-runner/docs/guides/deploying

Would be great to have a similar example for the second signer.

答案1

得分: 0

以下是您要翻译的代码部分:

const Lock = await ethers.getContractFactory("Lock");
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });

await lock.deployed();

现在我将使用两个签名者部署相同的 Lock 合同:

步骤 1:使用 Hardhat ethers 获取签名者。

const signers = await ethers.getSigners();

这将提供一个签名者数组。

步骤 2:使用第一个签名者进行部署:

const lock1 = await Lock.connect(signers[0]).deploy(unlockTime, { value: lockedAmount });

await lock1.deployed();

步骤 3:使用第二个签名者进行部署:

const lock2 = await Lock.connect(signers[1]).deploy(unlockTime, { value: lockedAmount });

await lock2.deployed();

还有一种方法是完全使用 ethers.js 来执行此操作。我在我的 GitHub 上有一个示例:https://github.com/codeTIT4N/axelar-two-way-nft-example/blob/main/scripts/deploy.js

英文:

Consider the example deploy script from the hardhat documentation:

const Lock = await ethers.getContractFactory("Lock");
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });

await lock.deployed();

Now I will deploy the same Lock contract using 2 signers:

Step 1: Get the signers using hardhat ethers.

const signers = await ethers.getSigners();

This gives an array of signers.

Step 2: Deploy using the first signer:

const lock1 = await Lock.connect(signers[0]).deploy(unlockTime, { value: lockedAmount });

await lock1.deployed();

Step 3: Deploy using the second signer:

const lock2 = await Lock.connect(signers[1]).deploy(unlockTime, { value: lockedAmount });

await lock2.deployed();

Another way is to do this entirely using ethers.js. I have an example of this on my GitHub: https://github.com/codeTIT4N/axelar-two-way-nft-example/blob/main/scripts/deploy.js

huangapple
  • 本文由 发表于 2023年3月15日 17:53:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743053.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定