0

can A call approve B to spend token though A have no tokens in his account? does function approve require to check balance of A?

1

can A call approve B to spend token though A have no tokens

Yes. approve() sets a spending limit but it is not necessarily funded.

does function approve require to check balance of A?

No. It merely sets the allowance.

In case this is counter-intuitive, it is because the balance check happens when the "spender" tries to exercise the privilege granted by approve.

This is acceptable.

  1. Alice has no money.
  2. Alice approves Bob to spend 100 tokens.
  3. Alice receives 100 tokens.
  4. Bob spends 100 tokens from Alice's account.

If Bob tries to spend more money than Alice has, then the transfer will fail.

Hope it helps.

  • 1
    You probably meant "tokens" instead of "wei". – smarx May 16 at 17:16
  • Good catch. Fixed it. – Rob Hitchens - B9lab May 16 at 18:27

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.