# Order of \_transfer and \_approve in transferFrom

**URL:** <https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909>\
**Category:** Contracts\
**Created:** [September 22, 2020, 6:57pm UTC](https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909 "2020-09-22T18:57:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Defiat](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Steven\_Defiat](https://forum.openzeppelin.com/u/Steven_Defiat)\
**Post date:** [September 22, 2020, 6:57pm UTC](https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909/1 "2020-09-22T18:57:16Z")

</div>

Hi guys,  
I have question, more for my understanding than anything.

Here's the **transferFrom** function in the ERC20 standard:

> function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {  
> \_transfer(sender, recipient, amount);  
> \_approve(sender, \_msgSender(), \_allowances[sender][\_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));  
> return true;  
> }

Shouldn't it be:

> function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {  
> **uint256 decreasedAllowance = allowance(account, \_msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");**  
> \_transfer(sender, recipient, amount);  
> \_approve(sender, \_msgSender(), decreasedAllowance );  
> return true;  
> }

(or even calling \_approve before the \_transfer)  
So that the 1st line triggers the condition (SafeMath) that the msg.sender has enough allowance.

??

Note:  
I also looked at the **burnFrom** function and it's implemented with the decreasedAllowance 1st, then approve, then \_burn.  
I wonder why it's not the case for transferFrom. (gas limits?)

Thanks for your explanations!

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [September 23, 2020, 6:05am UTC](https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909/2 "2020-09-23T06:05:32Z")

</div>

Hi @Steven_Defiat,

Welcome to the community 👋

Thanks for the question. The order of `_transfer` and `_approve` was discussed in the following issue:

> <https://github.com/OpenZeppelin/openzeppelin-contracts/issues/2030>
>
> Sorry, this is more of the question rather than a feature request or bug report.… 🙏
> 
> Referring to this commit https://github.com/OpenZeppelin/openzeppelin-contracts/commit/3a5da758767cfbcf256bdd147c56dbb0a2541569#diff-6202e31fca333ecfb19d878145bc8db5
> 
> The \`\_allowed\` method is moved to be after \`\_transfer\`. What is the rationale behind that @nventuro? (The allowance used to be reduced before doing the transfer.)
> !\[image\](https://user-images.githubusercontent.com/2575012/71337706-51b34980-257f-11ea-8f1b-88401ea3fd0d.png)
> 
> Should possible further actions that depend on allowance be checked by deducting the allowance first before committing to the actions?

Specifically:

> In the case of `ERC20` , the order is irrelevant because `_transfer` and `_approve` are independent and never call any other contract: they are executed atomically.

Let me know if you need more information.

---

<div class="post-metadata">

**Author:** ![Steven\_Defiat](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Steven\_Defiat](https://forum.openzeppelin.com/u/Steven_Defiat)\
**Post date:** [September 23, 2020, 1:10pm UTC](https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909/3 "2020-09-23T13:10:36Z")

</div>

Thanks a lot!  
It makes perfect sense.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [September 24, 2020, 12:07am UTC](https://forum.openzeppelin.com/t/order-of-transfer-and-approve-in-transferfrom/3909/4 "2020-09-24T00:07:15Z")

</div>

Hi @Steven_Defiat,

Feel free to ask all the questions that you need.

If you have a moment, it would be great if you could [introduce yourself](https://forum.openzeppelin.com/t/introduce-yourself-here/88/249).
