I am using remix and ganache and metamask and I encounter a confusing error. I compiled and deployed USDT at
0xdac17f958d2ee523a2206206994597c13d831ec7
on ganache with no problem. In order to do some test on it I wrote following contract in remix:
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/SafeERC20.sol";
contract testTether {
using SafeERC20 for IERC20;
IERC20 public token;
constructor(IERC20 _token) public {
token = _token;
}
function transfer(address to, uint256 amount) public {
token.safeTransfer(to, amount);
}
}
when I try to call transfer function I get:
Gas estimation failed: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Returned error: VM Exception while processing transaction: revert SafeERC20: low-level call failed
what is the problem?
Thanks in advance.
amount
larger than the balance of thefrom
account. – goodvibration Sep 8 '20 at 17:13approve
beforetransferFrom
, not beforetransfer
. – goodvibration Sep 8 '20 at 19:56testTether.transfer
will transfer tokens fromtestTether
contract balance. It doesn't move tokens frommsg.sender
. – Ismael Sep 9 '20 at 0:29testTether
contract. Is there any way to transfer token from one account to another directly using a smart contract function like my code above in a way that transaction fee be paid bysender account
not smart contract? – Kourosh Sep 10 '20 at 14:21