How to recover tokens sent to the token contract instead of a wallet?


I am playing around with a token smart contract on Mumbai net. I asked a friend to send back some of them and instead, he sent them to the contract.

The tokens are stuck in the contract here:

I have Approve and transferFrom, allowance, burnFrom etc. functions but they don't seem to work.

everything I try it says ',,,amount exceeds allowance'

Any idea?


Tokens sent to the token contract are lost unless there is a function specifically designed to retrieve them.

Wouldnt be possible to use TransferFrom function to retrieve them somehow?

Any idea how this function should look like? I see this is a common problem and it would be useful to have something like that in the contract

It is not possible to use transferFrom unless the contract is able to approve someone to execute the transferFrom.

You can designate a "recovery" address where any tokens sent can be transferred to, and then define a function like:

function recover(IERC20 token) public {
    SafeERC20.safeTransfer(token, recoveryAddress, token.balanceOf(address(this)));
1 Like