【问题标题】:Unable to create contract clone on Hardhat. "Error: Transaction reverted: function call to a non-contract account"无法在安全帽上创建合约克隆。 \"错误:交易恢复:对非合约账户的函数调用\"
【发布时间】:2022-09-20 01:44:44
【问题描述】:

我正在尝试使用 OpenZeppelin Clones 库创建一个克隆。但是,似乎安全帽无法识别创建的克隆合约地址。

相同的代码适用于 Remix,那么这与 Hardhat 有什么关系吗?注意:我也尝试过使用 Ganache,但是它会返回相同的错误。

这是我的工厂合同:

contract WhoopyFactory {

address immutable implementationContract;

address[] public allClones;

event NewClone(address indexed _instance);

mapping(address => address) public whoopyList;

constructor() { 
implementationContract = address (new Whoopy()); 
}

function createClone(address _whoopyCreator) payable external returns(address) { address clone = Clones.clone(implementationContract); Whoopy(clone).initialize(_whoopyCreator); 
emit NewClone(clone); 
return clone;
}

这是我正在运行的测试:

describe(\"Whoopy + WhoopyFactory\", function () {

it(\"Initialises contract correctly\", async function () {
const provider = new ethers.providers.JsonRpcProvider(\"HTTP://127.0.0.1:7545\")
const deployer = provider.getSigner(0); 
const player = provider.getSigner(1);

Whoopy = await ethers.getContractFactory(\"Whoopy\") 
whoopy = await Whoopy.deploy() 
await whoopy.deployed()

WhoopyFactory = await ethers.getContractFactory(\"WhoopyFactory\") 
wf = await WhoopyFactory.deploy() 
await wf.deployed()
wf.connect(player)

const tx = await wf.createClone(\"0x70997970C51812dc3A010C7d01b50e0d17dc79C8\")
console.log(tx)
const txReceipt = await tx.wait(1)
console.log(txReceipt)

这是恢复的错误:

Error: Transaction reverted: function call to a non-contract account
      at Whoopy.initialize (contracts/Whoopy.sol:117)
      at <UnrecognizedContract>.<unknown> (0x9f1ac54bef0dd2f6f3462ea0fa94fc62300d3a8e)

正如我之前所说,这段代码在 Remix 上可以正常工作。希望有人能指出我正确的方向。提前致谢!

    标签: ethereum ethers.js hardhat ganache openzeppelin


    【解决方案1】:

    据我了解,你在 Ganache 上部署智能合约,你可以使用 hardhat 自己的本地链,通过做 yarn chain 或 npx hardhat 节点,并将端口更改为 8545。 您可以通过替换以下内容使其更简单

    const provider = new ethers.providers.JsonRpcProvider("HTTP://127.0.0.1:7545")
    const deployer = provider.getSigner(0); 
    const player = provider.getSigner(1);
    

    const accounts = await hre.ethers.getSigners();
    const deployer = accounts[0];
    const player = accounts[1];
    

    并在部署时使用npx hardhat test --network localhost

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 2021-10-26
      相关资源
      最近更新 更多