I believe I have to use transferFrom function of ERC20. But I didn't get success. I also want to know will this approach show volume on chain for my contract address or I need to change the flow to EOA->smart contract->EOA.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8;
interface IERC20 {
function transfer(address _to, uint256 _value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
contract MyContract {
function sendUSDT(address _from, address _to, uint256 _amount) external returns (bool) {
IERC20 usdt = IERC20(address(0x2F7b97837F2D14bA2eD3a4B2282e259126A9b848));// mumbai testnet
return usdt.transferFrom(_from, _to, _amount);
}
function approve(address spender, uint256 value) external returns(bool) {
IERC20 usdt = IERC20(address(0x2F7b97837F2D14bA2eD3a4B2282e259126A9b848));
return usdt.approve(spender, value);
}
function balanceOf(address account) external view returns (uint256){
IERC20 usdt = IERC20(address(0x2F7b97837F2D14bA2eD3a4B2282e259126A9b848));
return usdt.balanceOf(account);
}
}