I'm looking for a way to withdraw tokens from a contract. Is that possible? I know how to withdraw basic tokens like eth and bnb from a smart contract but I want to withdraw tokens from a contract.


This works assuming your code includes the IERC20 library (this also works with BEP20 tokens ofc, they're essentially the same). It's trivial to modify it so you can withdraw only a certain amount or to another address.

function withdrawToken (address tokenAddress) public {
    IERC20 token = IERC20(tokenAddress);
    uint256 balance = token.balanceOf(address(this));
    token.transfer(msg.sender, balance);
  • Thank you so much, this was really helpful Jul 19 at 8:27

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.