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;

Transfer happens before approve. Or does the method fail and everything reverts back if anything in the method fails?

1 Answer 1


If a transaction is reverted at any point in the transaction, the whole transaction is reverted. In this case, .sub(amount) will revert if amount is larger than the allowance, so the token transfer will be reverted as well in that case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.