"Gas estimation false" instead fail with ""Balance is lower than withdrawal amount""
function withdrawTokens(address _token, address _to, uint _amount) public onlyOwner{
IERC20 token = IERC20(_token);
uint contractBalance = token.balanceOf(address(this));
require(contractBalance <= _amount, "Balance is lower than withdrawal amount");
token.transfer(_to, _amount);
}
Seems I use balanceOf wrong?
Your require has incorrect logic, you probably meant: require(contractBalance >= _amount); Also, that require is unnecessary, as the subsequent token.transfer() call will check that condition for you (assuming it's a properly written ERC20)
Обсуждают сегодня