Transferring USDC from smart contract to wallet


I have a small issue I'm hoping someone can resolve.

I have a contract that allows a user to deposit USDC into it. The user then gets an ERC20 token in exchange for it at a ratio of 1:1 (like a stablecoin).

When the user SELLS the ERC20 token, they get the equivalent value of USDC back into their wallet.

Those functions are working as planned.

When the user SELLS the ERC20 tokens, there is a FEE that the contract collects in USDC. I own the smart contract.

My question is how can I transfer the allocated USDC collected in fees to my wallet from the smart contract?

I have this code block in my contract

function transferERC20(IERC20 token, address to, uint256 amount) public {
        require(msg.sender == owner(), "You are not authorized to withdraw USDC from this contract.");
        uint256 erc20balance = token.balanceOf(address(this));
        require(amount <= erc20balance, "Insufficient Funds.");

When I call the function, the transfer SEEMS to go through (no errors); but the funds are NOT transferred to my wallet.

Thank you in advance for your assistance.


You will have to call the transfer function of the token, and send the amount from the contract address to your address, it’s exactly the same as how you are returning the users usdc. However you have no transfer function in the code you listed

1 Like

Thank you @CryptoWorld for your response. I appreciate it.

I'll try that now and get back with an update.



It worked. I appreciate it.

Take care and have a great day!


1 Like