transferFrom already checks the allowance, so does it make sense?


If you call it from an externally-owned account:

It is better to check the allowance in advance, because doing so can save you a bit of gas if it is insufficient and the transaction would subsequently revert.

If you call it from a smart-contract account:

Depending on how you want your contract function to behave - for example - you may want it to do something special if the allowance is insufficient.

  • if i’m calling it in a smart contract, does it save gas? – Donnoh Jan 3 at 13:25
  • 1
    @Donnoh: No, calling allowance in the smart contract actually costs more gas (though to the account which executes your contract function, which is not necessarily your account). But like I said, the decision on whether or not to check the allowance depends on what you want to do in case it is insufficient. There's usually nothing to do about it except reverting, thus, no reason to check the allowance, as transferFrom does that already. But you may, for example, want to avoid reverting, and instead do something else (mostly it isn't the case, but that's up for you to decide). – goodvibration Jan 3 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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