0

我不知道为什么传递函数不起作用。我尝试了 npx hardhat 测试,但传输时似乎失败了。

function deposit(address token, uint256 amount) external onlyOwner {
    uint256 balance = ERC20(token).balanceOf(msg.sender);
    console.log(token, balance);
    require(balance > amount, "not enough money to deposit");
    ERC20(token).approve(address(this), amount);
    ERC20(token).transferFrom(msg.sender, address(this), amount);
}

这是执行合约的安全 JavaScript 代码

await WETH.transfer(arb.address, ethers.utils.parseUnits("2", "ether"));

await IWETH.deposit({
  value: ethers.utils.parseUnits("100.0", "ether"),
});

await arb
  .connect(owner)
  .deposit(
    "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    ethers.utils.parseUnits("2", "ether")
  );

我好像失败了ERC20(token).transferFrom(msg.sender, address(this), amount);

4

0 回答 0