// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Timelock {
uint public constant duration = 365 days;
uint public immutable end;
address payable public immutable owner;
constructor(address payable _owner) {
end = block.timestamp + duration;
owner = _owner;
}
function deposit(address token, uint amount) external {
IERC20(token).transferFrom(msg.sender, address(this), amount);
}
receive() external payable {}
function withdraw(address token, uint amount) external {
require(msg.sender == owner, 'only owner');
require(block.timestamp >= end, 'too early');
if(token == address(0)) {
owner.transfer(amount);
} else {
IERC20(token).transfer(owner, amount);
}
}
}这是我以前使用过的牛奶合同:https://testnet.bscscan.com/token/0x8384b0ad2044e3b4c43c89c425d3ba4830b16f36
如果我想打电话给合同的存款函数,TimeLock,Metamask说:我们无法估计气体。合同中可能有错误,此事务可能失败。我将已部署的Milk合同的合同地址和函数保证金中的金额通过bscscan写入。我也设定了我作为所有者的元地址作为应付地址,我从那里部署合同,这是正确的吗?还是牛奶合同的地址?这是我的迁移js文件:
//const Migrations = artifacts.require("Migrations");
const Timelock = artifacts.require("Timelock");
module.exports = function (deployer) {
// deployer.deploy(Migrations);
deployer.deploy(Timelock,"0xec125D397cdA00f7390c1C6E76d4ca9902357fd3");
};我认为问题在于存款函数中的IERC20。为什么我需要进口I 20溶胶而我需要它们?为什么我不能写函数,为什么Metamask不能估计Gas?任何帮助都将不胜感激。在失败的tx散列下面:https://testnet.bscscan.com/tx/0x9ff191b4725781dc7174c58bb94fdfc61d4bbc484b04b21f61216ff822acda8f
发布于 2023-01-02 03:16:22
事务恢复是因为您忘记批准TimeLock协议(地址0x91492C12C43a5dd018e32EA6b66178eCC71e22BF)以使用Milk令牌:Milk.allowance(0xec125D39..your_address, 0x91492C..TimeLock_address) = 0
要做到这一点,您需要调用approve(timelock_address, amount)的帐户,您将调用存款。例如,要使失败的事务正常工作,您需要在Milk令牌契约上调用它:
approve(0x91492C12C43a5dd018e32EA6b66178eCC71e22BF, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)您可以使用WriteContract按钮在牛奶令牌的的扫描上完成该操作。
https://ethereum.stackexchange.com/questions/142152
复制相似问题