I want to write a contract that buys back an ERC20 Token using USDC. (in REMIX IDE)
I want to understand what is the best practice for paying out the USDC in return for the ERC20 that was sold to the contract.
Right now, I am calling a
usdcAddress.transferFrom(address(buyer), msg.sender, price);
It just dawned on me that I need to the buyer wallet address to call approve()
before I can call the transferFrom()
which is something I cannot do in production. Only the msg.sender
will be able to call approve via the web3.
I am thinking of just sending this contract of mine USDC, so the payout will come directly from the contract, instead of a separate wallet, and will enable me to just call transfer()
with msg.sender
being my buyer contract. Will this work? Is this a good approach? Can a smart contract hold/own USDC(or other tokens) ?