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.
amountlarger than the balance of thefromaccount. – goodvibration Sep 08 '20 at 17:13approvebeforetransferFrom, not beforetransfer. – goodvibration Sep 08 '20 at 19:56testTether.transferwill transfer tokens fromtestTethercontract balance. It doesn't move tokens frommsg.sender. – Ismael Sep 09 '20 at 00:29testTethercontract. 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 accountnot smart contract? – Kourosh Sep 10 '20 at 14:21approvewith the contract address and amount to spend, then the contract can calltransferFromon behalf of the token's owner. See this question https://ethereum.stackexchange.com/questions/46457/send-tokens-using-approve-and-transferfrom-vs-only-transfer for more details. – Ismael Sep 10 '20 at 19:22