Hi! I am also new to the blockchain space and working on a dApp with a team. We are currently trying to use the openZepplin IERC20 interface to send USDC in our smart contract. We’re having some trouble figuring out how to use it on the Ropsten testnet. We found the contract address of a test USDC token and have been able to call the IERC20 function on it and view our wallets usdc balance. However we are struggling to figure out how and where to call the token.approve function. Whenever we call it in the same function or even from a separate contract, calling transferFrom still gives us an error, not enough funds approved, and calling token.allowance returns 0. Any help would be greatly appreciated thanks!!
Here is some sample code below of what we want to do with the IERC20 interface:
contract usdcSending{
address public sender;
address public usdcContractAd = 0x0D9C8723B343A8368BebE0B5E89273fF8D712e3C;
uint256 public heldAmount = 0;
uint256 public approvedFunds = 0;
IERC20 token = IERC20(contractAd2);
constructor() public{
sender = msg.sender;
heldAmount = token.balanceOf(sender);
}
function payIn(uint256 amount) public{
token.approve(address(this), 100); //doesn't seem to work
approvedFunds = token.allowance(sender, address(this));
heldAmount = token.balanceOf(sender);
token.transferFrom(msg.sender, address(this), amount);
}
function payOut(address recipient, uint256 amount) public{
token.transferFrom(address(this), recipient, amount);
}
}