Transfer function in the USDT contract

hi @abcoathup

how’s about the other methods (Can not call the function approve() of the USDT contract)? i mean how do i call transfer method?

thx

1 Like

Hi @trongdth,

Welcome to the community :wave:

You should be able to call ERC20 functions such as transfer using SafeERC20 such as safeTransfer.

1 Like

Thanks @abcoathup. But I am facing the problem when transferring USDT token from my smart contract to another wallet address by using safeTransferFrom. It runs ok when I call that method from wallet address to smart contract. Thanks for your help.

1 Like

anw, i can manage this problem. tyvm for your help @abcoathup

1 Like

Hi @trongdth,

I’m glad you were able to resolve.

Hi @abcoathup,

This is the javascript code I’m using to call myContract function fetchTokens(...), which fetches specified amount of USDT from specified array of user addresses to MyContract. I’m using SafeERC20 for IERC20, to call safeTransferFrom(...) on USDT token contract instance.

await myContract.methods
  .fetchTokens(
    CONSTANTS.TETHER_ADDRESS,
    [accounts[0], accounts[1], accounts[2], accounts[3], accounts[4]],
    [
      "10000000000000000000",
      "10000000000000000000",
      "10000000000000000000",
      "10000000000000000000",
      "10000000000000000000",
    ]
  )
  .send({
    from: accounts[0],
    gasLimit: 6000000,
  });

And this is the relevant .sol code of MyContract:

contract MyContract is Ownable, Pausable {
using SafeERC20 for IERC20;
...
IERC20 public ERC20Instance;
...
function fetchTokens(
    address _tokenAddress,
    address[] memory _userAddresses,
    uint256[] memory _tokenAmounts
) public payable returns (bool) {
        ERC20Instance = ERC20(_tokenAddress);
        for (uint256 i = 0; i < _userAddresses.length; i++) {
            if (
                ERC20Instance.allowance(_userAddresses[i], address(this)) >=
                _tokenAmounts[i]
            ) {
                ERC20Instance.safeTransferFrom(
                    _userAddresses[i],
                    address(this),
                    _tokenAmounts[i]
                );
            } else {
                emit TokenFetchFailed(
                    _tokenAddress,
                    _userAddresses[i],
                    _tokenAmounts[i]
                );
            }
        }
    emit TokensFetched(_tokenAddress, _userAddresses, _tokenAmounts);
    return true;
 }
}

Now, the problem here is, that the execution of the javascript code gets stuck at the await call above. The code does work, i.e. the relevant USDT are transferred from those users to MyContract, but no code written below this await call gets executed.

My hunch is it could be a problem with the return value from the transferFrom( ) of USDT contract. Because, without using SafeERC20 for IERC20, this transferFrom( ) was throwing an error of ‘Improper return’ (which I came to know on truffle debugging), which SafeERC20 seems to have somehow covered up.

This is the USDT contract I’ve forked on ganache mainnet, that I’m interacting with.

How do I continue the javascript code execution, after the call to the javascript code above?