【发布时间】:2022-01-20 10:46:33
【问题描述】:
我有来自 HardHat 教程https://hardhat.org/tutorial/writing-and-compiling-contracts.html的智能合约
我成功部署了它。
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
const Token = await ethers.getContractFactory("Token");
const token = await Token.deploy();
console.log("Token address:", token.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
但是只有联系人的地址返回给我,它的私钥没有。
console.log("Deploying contracts with the account:", deployer.address);
我怎样才能以这种方式获取私钥? 我需要它的方法
web3.eth.accounts.wallet.add('0x<private_key>');
因为否则我无法调用智能合约上的转账方法。
【问题讨论】:
标签: javascript ethereum smartcontracts web3js hardhat