英文:
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
答案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;
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论