I am deploying a contract today.
Tomorrow if some user mistakenly sends ETH to my contract, I can retrieve or return it if I have implemented a payable and a send function.
@external @payable def __default__(): # a basic payable to enable receiving incoming eth log ethReceived(msg.value, msg.sender) @external def withdraw(_to: address): # for sending out any eth transferred in by mistake assert msg.sender == self.owner log ethSent(self.balance, msg.sender) send(_to, self.balance)
But what if some user mistakenly sends any other ERC-20 token or ERC-721 NFT to my contract; is there a general function I could have implemented in my contract, so I can retrieve those, as long as they follow their respective standards? I won't know the token contract in advance, it could be any valid ERC-20 or ERC-721.
Vyper code preferred, but Solidity answers or examples are also fine.