# Allowance shows value, token contract says insufficient allowance

**URL:** <https://forum.openzeppelin.com/t/allowance-shows-value-token-contract-says-insufficient-allowance/34851>\
**Category:** Smart Contracts\
**Tags:** erc20, solidity\
**Created:** [February 22, 2023, 11:28am UTC](https://forum.openzeppelin.com/t/allowance-shows-value-token-contract-says-insufficient-allowance/34851 "2023-02-22T11:28:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Da\_Knocker](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/da_knocker/32/17743_2.png) [@Da\_Knocker](https://forum.openzeppelin.com/u/Da_Knocker)\
**Post date:** [February 22, 2023, 11:28am UTC](https://forum.openzeppelin.com/t/allowance-shows-value-token-contract-says-insufficient-allowance/34851/1 "2023-02-22T11:28:45Z")

</div>

Hi, i am working on a side game contract. This contract receives tokens from another contract, when the contracts balance has reached an minimum amount of tokens, the first caller to call the function, will burn the balance of tokens and receives 1% of the balance as reward for doing so.

In order to approve the caller to spend the contract's token balance, i used this:

```auto
  function approve() public {
    approveBurn(msg.sender);
  }

  function approveBurn(address spender) internal {
    // Add some (alot) extra allowance in case more comes in
    uint256 extraAllowance = erc20Token.balanceOf(address(this)) * 100**18;
    uint256 amount = erc20Token.balanceOf(address(this)) + extraAllowance;
    erc20Token.approve(spender, amount);
    emit Approval (address(this), spender, amount);
  }

```

When i go to the erc20 token contract, and check the callers allowance, it shows the correct amount (so the games balance \* 100). So according to the erc20 token contract, caller have enough allowance to spend the games balance.

However, when the caller calls the function to burn the balance and receive the reward, done with this:

```auto
   IBurnableToken(erc20Token).burn(address(this), toBeBurned);
   erc20Token.transferFrom(address(this), caller, callerReward);

```

It reverts with "Unsufficient allowance", but when i check allowance on the token contract, the allowance for caller to spend the balance, is there, even multiplied by 100 times.

I am a bit lost here, anyone have a direction where to search?

---

<div class="post-metadata">

**Author:** ![barakman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/barakman/32/855_2.png) [@barakman](https://forum.openzeppelin.com/u/barakman)\
**Post date:** [February 22, 2023, 1:52pm UTC](https://forum.openzeppelin.com/t/allowance-shows-value-token-contract-says-insufficient-allowance/34851/3 "2023-02-22T13:52:01Z")

</div>

> [@Da\_Knocker](#):
>
> When i go to the erc20 token contract, and check the callers allowance...

Where exactly is that?

* * *

Also note that you don't even need an approval here to begin with, as you may as well change this:

```auto
   erc20Token.transferFrom(address(this), caller, callerReward);

```

To this:

```auto
   erc20Token.transfer(caller, callerReward);

```

* * *

Also note that this:

```auto
    uint256 extraAllowance = erc20Token.balanceOf(address(this)) * 100**18;
    uint256 amount = erc20Token.balanceOf(address(this)) + extraAllowance;

```

Is equivalent to this:

```auto
    uint256 amount = erc20Token.balanceOf(address(this)) * (100**18 + 1);

```

And hence to this:

```auto
    uint256 amount = erc20Token.balanceOf(address(this)) * (10**36 + 1);

```

---

<div class="post-metadata">

**Author:** ![Da\_Knocker](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/da_knocker/32/17743_2.png) [@Da\_Knocker](https://forum.openzeppelin.com/u/Da_Knocker)\
**Post date:** [February 22, 2023, 2:09pm UTC](https://forum.openzeppelin.com/t/allowance-shows-value-token-contract-says-insufficient-allowance/34851/4 "2023-02-22T14:09:58Z")

</div>

Hi, thanks for your reply. I changed

```auto
erc20Token.transferFrom(address(this), caller, callerReward);

```

to

```auto
erc20Token.transfer(caller, callerReward);

```

and also used

```auto
  uint256 constant MAX_INT = 2**256 - 1;

```

as approval now.

When i delete

```auto
IBurnableToken(erc20Token).burn(address(this), toBeBurned);

```

then the function works but will only send 'calledReward' to caller. When i add the code above back, it throws i have insufficient allowance. What i try to do, is that by calling the function, the balance of the contract gets burned minus 1% of the total balance, which will be send to the caller.

Function that the caller can call:

```auto
  function burnThePool() public {
   // Set requirement to execute
   require (erc20Token.balanceOf(address(this)) >= minimumToBurn, "Minimum not reached yet");
   executeBurn(msg.sender);   
  }

```

and then the internal function:

```auto
  function executeBurn(address caller) internal {
   // Calc the reward for the caller
   uint256 callerReward = erc20Token.balanceOf(address(this)) / 100 * callerPercentage;
   // Calc the amount to be actually burned
   uint256 toBeBurned = erc20Token.balanceOf(address(this)) - callerReward;
   // Update gamedata for caller
   gameData[caller].burnedPool += 1;
   gameData[caller].totalBurned = gameData[caller].totalBurned + toBeBurned;
   gameData[caller].erc20Collected = gameData[caller].erc20Collected + callerReward;
   // Check if caller burned the most of all burns
   if (toBeBurned > biggestBurn) {
      biggestBurn = toBeBurned;
      // Set caller as new `biggestBurner`
      biggestBurner = caller;
   }
   burnedByGame = burnedByGame + toBeBurned;
   // Fire everything up
   IBurnableToken(xenToken).burn(address(this), toBeBurned);
   erc20Token.transfer(caller, callerReward);
  }

```

I made a public function that executes an internal function, so that msg.caller in the internal function, will be the contract its self. So im not sure why the burn part of the code, throws us unsufficient allowance, since the tokens are in the contracts balance and the contract makes the internal call.
