# How Do Approve Transactions Impact Wallet Balances?

**URL:** <https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679>\
**Category:** Developers\
**Tags:** Discussing, nns\
**Created:** [February 19, 2024, 10:23am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679 "2024-02-19T10:23:55Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 10:23am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/1 "2024-02-19T10:23:55Z")

</div>

How does the approval of transactions affect balance calculations? Consider a scenario with four transactions involving two accounts:

1. Transaction 1: Account A mints 50 tokens. **[MINT TX]**
2. Transaction 2: Account A transfers 20 tokens to Account B. **[TRANSFER TX]**
3. Transaction 3: Account A approves the transfer of 10 tokens to Account B. **[APPROVE TX]**
4. Transaction 4: Account B transfers 10 tokens to Account C. **[TRANSFER TX]**

What should the balances of Accounts A and B be?

I’m asking this to gain insight into how “Approve” type transactions function. For context, here’s an example of such a transaction: [transaction](https://dashboard.internetcomputer.org/transaction/e6aa67e2a6eaeb7bc477296cc32b1314cafcceec31d52569e32bb6e6848e82b6?index=10498156)

How does an “Approve” transaction impact wallet balances, and how can a spender utilize the approved transaction amount? Furthermore, why is this type of transaction necessary in the first place?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 19, 2024, 10:29am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/2 "2024-02-19T10:29:07Z")

</div>

An approval costs the same amount as a transfer that transfers 0 tokens, i.e. just the transaction fee. For ICP that’s 0.0001 ICP. The spender is then allowed to transfer the approved amount as if it were their own tokens.

Approvals are very useful since there is no automatic notification mechanism when an account receives a transfer. So in most cases it’s easiest to just let the canister that needs to be notified of a transaction to do the TX on its own instead of doing the transfer and then notifying the receiver of the transfer. The work is mostly the same, but error handling becomes much easier that way

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 10:35am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/3 "2024-02-19T10:35:42Z")

</div>

So, if I understand correctly, after the completion of all four transactions, the balances would appear as follows:

- Account A: 30 tokens
- Account B: 10 tokens

Am I correct in assuming that Account A’s approval allows Account B to spend 10 tokens, yet these tokens won’t immediately reflect in their respective balances? Furthermore, can Account B transfer these 10 tokens to another account, say Account D, given the authorization granted by Account A?

Edit: i’m ignoring transaction fees here. just trying to understand main transfer logic.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 19, 2024, 10:40am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/4 "2024-02-19T10:40:11Z")

</div>

Yes, that’s right. An approval does not affect the balance because it only approves someone else to spend token. They can then use `icrc2_transfer_from` to actually perform the transfer

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 10:43am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/5 "2024-02-19T10:43:19Z")

</div>

Would these approved tokens be locked?

Continuing with the example, in Account A, there are still 30 tokens, with 10 tokens allocated to Account B. Are these tokens subject to locking? Moreover, what would occur if Account A were to transfer all 30 tokens to another account before Account B utilizes the allocated 10 tokens?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 19, 2024, 10:46am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/6 "2024-02-19T10:46:11Z")

</div>

The standard does not require tokens to be locked, although I don’t think it would be forbidden. Also, while the standard does not allow infinite approvals, you can approve more than the current balance, so you can create effectively infinite approvals by approving e.g. `u128::MAX`.

When there are not enough tokens in the account for a transfer then whoever tries to transfer (no matter if it’s the owner or an approved spender) will receive an `InsufficientFunds` error.

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 10:48am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/7 "2024-02-19T10:48:39Z")

</div>

Clear now, thanks for the insight!

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 11:51am UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/8 "2024-02-19T11:51:56Z")

</div>

@Vivienne I have one more question for clarification regarding fee calculation. As you mentioned, during an APPROVE transaction, fees are deducted from the account that approves the transaction. So, if Account A approves tokens for Account B, fees will be deducted from Account A.

Now, when Account B uses the `transfer_from` method to access those tokens, it becomes a regular “TRANSFER” type transaction from Account A to Account B. In this scenario, what happens with fee deduction? Is the fee deducted twice?

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 19, 2024, 12:09pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/9 "2024-02-19T12:09:14Z")

</div>

Additionally, could you clarify how the `from` and `to` parameters function?

In an “APPROVE” transaction, the `from` address will be Account A, and there won’t be a `to` address specified. Account B will act as the spender.

When Account B later utilizes the `transfer_from` method, resulting in a “TRANSFER” type transaction, which address will be designated as the `from` address? Will it be Account A or Account B?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 19, 2024, 12:39pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/10 "2024-02-19T12:39:20Z")

</div>

> [@jaesharma](#):
>
> Now, when Account B uses the `transfer_from` method to access those tokens, it becomes a regular “TRANSFER” type transaction from Account A to Account B. In this scenario, what happens with fee deduction? Is the fee deducted twice?

The `approve` costs you the fee one time, and then every `transfer_from` also costs 1x the fee. Also, if you approve 10 and then 10x `transfer_from` only 1 token then you pay the fee 11 times (1x approve, 10x transfer).

> [@jaesharma](#):
>
> When Account B later utilizes the `transfer_from` method, resulting in a “TRANSFER” type transaction, which address will be designated as the `from` address? Will it be Account A or Account B?

It will show up as a transfer from A since the funds come out of account A

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 20, 2024, 12:42pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/11 "2024-02-20T12:42:36Z")

</div>

Also, Once we’ve approved a certain number of tokens, is it correct that we can’t reverse this decision if we later want to unapprove them? once approved, then tokens belong to the spender right?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 20, 2024, 12:49pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/12 "2024-02-20T12:49:43Z")

</div>

From the [spec](https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/README.md#icrc2_approve):

> The call resets the allowance and the expiration date for the `spender` account to the given values.

So no, you can unapprove later

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 20, 2024, 1:21pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/13 "2024-02-20T13:21:57Z")

</div>

ohh ok. can you help me how exactly? I’ve explored nns.ic0.app but haven’t located the transaction options for “APPROVE” or “UNAPPROVE.” By default, the transaction type available on NNS appears to be “TRANSFER.”

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 20, 2024, 1:25pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/14 "2024-02-20T13:25:21Z")

</div>

AFAIK the NNS dapp does not support approvals at the moment.

`unapprove` would be `approve` but for `0` tokens.

---

<div class="post-metadata">

**Author:** ![jaesharma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaesharma/32/7297_2.png) [@jaesharma](https://forum.dfinity.org/u/jaesharma)\
**Post date:** [February 20, 2024, 1:34pm UTC](https://forum.dfinity.org/t/how-do-approve-transactions-impact-wallet-balances/27679/15 "2024-02-20T13:34:39Z")

</div>

so basically the “approve” transaction, it seems it’s more of an update rather than a conventional transaction; it serves as a mapping of an account against a certain number of tokens.

This implies that if I approve an account to spend 10 tokens, and then later approve the same account for 5 tokens, the spender can only utilize 5 tokens, not a cumulative 15. The approve transaction overwrites rather than adds to the previous approval limit.
