# Explain the practical use of increaseAllowance and decreaseAllowance functions on ERC20

**URL:** <https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103>\
**Category:** Contracts\
**Tags:** erc20, openzeppelin-contracts\
**Created:** [September 5, 2021, 3:33pm UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103 "2021-09-05T15:33:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![levitojo](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@levitojo](https://forum.openzeppelin.com/u/levitojo)\
**Post date:** [September 5, 2021, 3:33pm UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/1 "2021-09-05T15:33:43Z")

</div>

Hi,

I used the ERC20 implementation of openzeppelin contracts on my test token and I've found two functions which really confused me: increaseAllowance and decreaseAllowance

#### 🔢 The Code

```auto
    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve( _msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero" );
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }
        return true;
    }

```

Someone please explain the practical utility of this function in a renounced contract.

Thanks.

---

<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:** [September 6, 2021, 1:28am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/2 "2021-09-06T01:28:13Z")

</div>

Hi, for example, if Alice approves Bob to spend 100 token at first, but later, Alice would like to only approve Bob to spend 50 token, so Alice will send two transfer:

- Alice approves Bob 100 token. _(token.approve(Bob\_Address, 100))_
- Alice approves Bob 50 token. _(token.approve(Bob\_Address, 50))_

So if Bob finds these two transactions, he can make a transaction between these two transactions to spend more 100 token. That is:

- Alice approves Bob 100 token. _(token.approve(Bob\_Address, 100))_
- Bob spends Alice 100 token. _(token.transferFrom(Alice\_Address, Bob\_Address, 100))_
- Alice approves Bob 50 token. _(token.approve(Bob\_Address, 50))_
- Bob spends Alice 100 token. _(token.transferFrom(Alice\_Address, Bob\_Address, 50))_

So for Alice, she only wants to approve Bob 50 token actually, but Bob finally get 150 token, so the function `increaseAllowance` and `decreaseAllowance` come.

And for more details, I think you can have a look at the discuss at here: [https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729](https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729)

---

<div class="post-metadata">

**Author:** ![levitojo](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@levitojo](https://forum.openzeppelin.com/u/levitojo)\
**Post date:** [September 6, 2021, 6:29am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/3 "2021-09-06T06:29:58Z")

</div>

In the general case of an ERC-20 token, the approvers are uniswap / pancake routers and they probably don't use these functions, right ?

They just approve a large number as allowance so the user could buy more and not have to allow the uniswap protocol after every buy.

Please correct if my understanding is wrong.

---

<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:** [September 6, 2021, 6:31am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/4 "2021-09-06T06:31:51Z")

</div>

Yes, you are right. Just approve a large number

---

<div class="post-metadata">

**Author:** ![levitojo](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@levitojo](https://forum.openzeppelin.com/u/levitojo)\
**Post date:** [September 6, 2021, 6:35am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/5 "2021-09-06T06:35:22Z")

</div>

So, in general erc-20 / bep-20 tokens coming up on these exchanges, the increaseAllowance and decreaseAllowance functions are not used. 😂

But I think the front-running protection concept using these functions still seem theoretical.

---

<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:** [September 6, 2021, 7:13am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/6 "2021-09-06T07:13:38Z")

</div>

Emmmm, they can use increaseAllowance and decreaseAllowance, but some tokens can not increase form a non-zero value.  
If user want to swap some USDT to get 1 Eth, assume 1 eth = 100 USDT, cause there will be slippage, so you are expect to approve a larger amount, maybe call `increaseAllowance(110)`, but actually, you only spend 105 USDT to get 1 ETH, so now, the allowance becomes to 5, and then you want to do this again, so you call `increaseAllowance(110)` again, but for this time, it will fail, cause it can not approve form a non-zero value to another non-zero value, so for these tokens, if you still want to use `increaseAllowance()`, you need some extra logic. It will be more complex, so just approve max is convenient.  
You can use increaseAllowance and decreaseAllowance, but need more logic to solve such situation.

Hope I have made myself clear.

---

<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:** [March 3, 2022, 4:56am UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/7 "2022-03-03T04:56:33Z")

</div>

5 posts were split to a new topic: [Token transfer rejected](https://forum.openzeppelin.com/t/token-transfer-rejected/25587)

---

<div class="post-metadata">

**Author:** ![PoorMillionaire](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/poormillionaire/32/15843_2.png) [@PoorMillionaire](https://forum.openzeppelin.com/u/PoorMillionaire)\
**Post date:** [July 27, 2022, 3:21pm UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/8 "2022-07-27T15:21:54Z")

</div>

Do I understand this correctly that if you have to use increaseAllowance, and then transfer that these are two separate transactions and user have to pay double fee?

I have my own smart contract and user send funds to my smart contract, but he needs to first pay fee for increaseAllowance and then another fee for transfer? This is really inconvenient... can this be solved another way?

---

<div class="post-metadata">

**Author:** ![DVYNE\_ETH\_O1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/dvyne_eth_o1/32/18622_2.png) [@DVYNE\_ETH\_O1](https://forum.openzeppelin.com/u/DVYNE_ETH_O1)\
**Post date:** [May 26, 2023, 1:07pm UTC](https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/9 "2023-05-26T13:07:10Z")

</div>

OKAY i kinda get it but why can anyone call the increase and decrease alowance function  
shouldnt it be only the person who deployed the contract
