Hello, I am new to solidity and smart contracts, I would like to create a contract that can send ERC20 tokens from one address to another address. I used this function
function transferFromERC20(IERC20 token, address from, address payable to, uint256 amount) public payable {
uint256 erc20balance = token.balanceOf(from);
uint256 erc20allowance = token.allowance(from, address(this));
token.approve(from, amount);
require(amount <= erc20balance, "balance is low");
token.transferFrom(from, to, amount);
emit TransferSent(msg.sender, to, amount);
}
but I got the error "Fail with error 'Allowance is not enough'
" When I tried to send transaction, anyone can help me about this I loss a lot of USDT for gas fee when try this