我正在为我的合同在Kovan网络上写测试。为了做到这一点,我使用了hardhat的叉特性,并将以下内容添加到hardhat.config.js文件中:
module.exports = {
solidity: "0.8.0",
defaultNetwork: "hardhat",
networks: {
hardhat: {
forking: {
url: INFURA_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
}
}
};INFURA_URL指向Kovan上的节点。PRIVATE_KEY是我想要部署的Kovan帐户的关键。当我直接部署到Kovan但不部署到分叉节点时,这个变量工作得很好。
在我的部署脚本中,我执行以下操作:
const [deployer] = await ethers.getSigners();但是,我的deployer不是对应于配置中的私钥的帐户。这是一个正确的帐户,当我直接部署到科万。
不知道为什么会发生这种情况,科万的叉子不支持在草帽上?
发布于 2022-07-20 14:40:15
对我来说,它的工作方式是忘记草帽,完全依赖ethers,因为我创建了一个指定私钥和提供者的Signer,如下所示:
import { providers, Wallet } from 'ethers';
require('dotenv').config();
const main = async() => {
const providerLocal = new
providers.JsonRpcProvider("http://127.0.0.1:8545");
const owner = new Wallet(process.env.DEPLOYER_PRIVATE_KEY as string, providerLocal);
console.log(`The wallet ${owner.address} will deploy this contract`)
const MyContract = await ethers.getContractFactory('MyContract');
const mycontract = await MayContract.connect(owner).deploy();
}
main();https://stackoverflow.com/questions/67011645
复制相似问题