如何使用 ethers.js 获取合约部署者地址?

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

How to get contract deployer address using ethers.js?

问题

我想知道在合约部署后获取合约部署者地址的方法。

    let contract = await factory.deploy
     (name, name + "NFT");
     await contract.deployed();
     let deployer = contract.deployTransaction.from;
我可以通过部署合约来获取部署者地址。
但我需要在后端获取。
期待您的回复。

谢谢 :)
英文:

I wanna know the way to get contract deployer address after contract deployed.

let contract = await factory.deploy
 (name, name + "NFT");
 await contract.deployed();
 let deployer = contract.deployTransaction.from;

I can get deployer using deploy contract.
But I need to get in backend.
Looking forward to hearing from you.

Thank you 如何使用 ethers.js 获取合约部署者地址?

答案1

得分: 0

这里有一个可工作的示例:

import { ethers } from "hardhat";

async function main() {
  const Contract = await ethers.getContractFactory("Contract");
  const contract = await Contract.deploy();
  await contract.deployed();
  
  console.log("合约部署到: ", contract.address);    
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
英文:

Here you have a working example:

import { ethers } from "hardhat";

  async function main() {
    const Contract = await ethers.getContractFactory("Contract");
    const contract = await Contract.deploy();
    await contract.deployed();
    
    console.log("Contract deployed to: ", contract.address);    
    
    }
    
  main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
  });

huangapple
  • 本文由 发表于 2023年2月18日 14:42:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491656.html
匿名

发表评论

匿名网友

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

确定