I’m experimenting with a presale contract based on the BSC testnet, and in the contract I’m attempting to achieve the purchase of my token with USDT.
Using my own code within the contract itself, I cannot get approval to go through properly for the contract to spend my USDT. However if I use the approve function within the “write contract” section of the USDT token on BSCSCAN, it does work - and I can buy tokens after approval went through.
Example of my approval code which does not work:
function approveUSDT() public {
IERC20 usdtToken = IERC20(0x337610d27c682E347C9cD60BD4b3b107C9d34dDd);
require(usdtToken.approve(address(this), tokenAmount), "Approval failed");
emit ApprovalSuccessful(msg.sender, tokenAmount);
}
What am I missing here?