0

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.

What is the best practice to implement this scenario.

2
  • Some tokens interpret token.approve(type(uint256).max, operator) as the owner approving operator to make infinite withdrawals with transferFrom. Unfortunately it doesn't seems to be the case for the current USDC implementation.
    – Ismael
    May 11 at 4:11
  • thanks for this. however, I do not want to call approve on the contract itself, I'd much rather have this done on web3 by the actual user interacting with my contract.
    – momoja
    May 11 at 8:44

2 Answers 2

0

Well this may not be the best way but you can do this in 2 steps instead of doing this in 1 step . Example : Step1 : Seller deposits the ERC20 token to smart contract first. Step2 : Buyer take ERC20 token from smart contract and in same function buyer will be sending USDC to the seller as well.

1
  • Thanks for this, however, only the seller of the token is the live person here. I want my contract/wallet to automatically transfer the USDC as payment to the address that sold its tokens.
    – momoja
    May 10 at 5:34
0

What I ended up doing is deciding to just regularly send in USDC to my contract, and just call transfer() from there. If there are any other suggestions, it's still welcome. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.