# Fail with error 'SafeERC20: ERC20 operation did not succeed'

**URL:** <https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164>\
**Category:** Smart Contracts\
**Tags:** erc20\
**Created:** [November 16, 2022, 7:04pm UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164 "2022-11-16T19:04:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dani92](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@Dani92](https://forum.openzeppelin.com/u/Dani92)\
**Post date:** [November 16, 2022, 7:04pm UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164/1 "2022-11-16T19:04:08Z")

</div>

Hello,  
I try to withdraw matic tokens from my smart contract, that I deployed on mumbai testnet.  
My withdraw functions looks like this:

```auto
function withdrawOnlyOwner(address token) public onlyOwner {
        IERC20 token_transfer = IERC20(token);
        uint256 transfer_amount = balance(token);
        require(transfer_amount > 0, "Balance too low");
        SafeERC20.safeTransfer(token_transfer, owner, transfer_amount);
        emit Withdrawal(owner, transfer_amount);
    }

```

balance is a public function that works correctly, I get the balance of the token I put the address in.

If I run the .js code snippet to withdrwa all funds from the contract, the code works correctly. But I do not get the tokens and if I do have a look at the transaction [here].([https://mumbai.polygonscan.com/tx/0xceada0fe6fa8ffe95d90e033c9bb221dc3ce8907408510871424147f4ca91933](https://mumbai.polygonscan.com/tx/0xceada0fe6fa8ffe95d90e033c9bb221dc3ce8907408510871424147f4ca91933))  
Does someone have an idea what is going wrong here?

---

<div class="post-metadata">

**Author:** ![warrior\_dragon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/warrior_dragon/32/16359_2.png) [@warrior\_dragon](https://forum.openzeppelin.com/u/warrior_dragon)\
**Post date:** [November 17, 2022, 1:25am UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164/2 "2022-11-17T01:25:36Z")

</div>

Dear @Dani92  
If possible, could you share whole codebase of your smart contract?  
Kind regards.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 17, 2022, 1:39am UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164/3 "2022-11-17T01:39:50Z")

</div>

Hi, welcome to the community! 👋

> [@Dani92](#):
>
> matic tokens

I am not sure for your `Matic token`, but is it an original coin, just like ETH, use it as gas fee, or a token, just like DAI? I tend to think it is just like ETH, so maybe you can not use `SafeERC20.safeTransfer`, just `recipientAddress.transfer(amount)`

---

<div class="post-metadata">

**Author:** ![Dani92](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@Dani92](https://forum.openzeppelin.com/u/Dani92)\
**Post date:** [November 17, 2022, 7:27am UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164/4 "2022-11-17T07:27:20Z")

</div>

Yes it is the main token on polygon (0x0000000000000000000000000000000000001010). It should be the same like eth on ethereum. But why should this not work with safeTransfer? Thats what I don't understand.

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [November 28, 2022, 4:10pm UTC](https://forum.openzeppelin.com/t/fail-with-error-safeerc20-erc20-operation-did-not-succeed/33164/5 "2022-11-28T16:10:36Z")

</div>

What is `balance(token)` ?
