Blockchain Developer Token Standards and Creation 2 — Questions and Answers
Question 1: Which ERC-20 function returns the number of tokens a spender is still allowed to withdraw from an owner's account?
- allowance(owner, spender) (Correct answer)
- balanceOf(owner)
- approve(spender, amount)
- transferFrom(from, to, amount)
Correct answer: allowance(owner, spender)
allowance(owner, spender) returns the remaining amount the spender is permitted to withdraw.
Question 2: In ERC-20, what is the well-known race-condition risk associated with the approve() function?
- A spender can front-run a changed approval and spend both the old and new amounts (Correct answer)
- It permanently locks the owner's balance
- It mints unlimited tokens
- It bypasses the totalSupply cap
Correct answer: A spender can front-run a changed approval and spend both the old and new amounts
Changing an existing non-zero allowance lets a spender front-run and use both old and new amounts.
Question 3: What does the ERC-20 decimals() function actually control?
- Only the display formatting of token amounts off-chain (Correct answer)
- The on-chain divisibility enforced by the contract
- The maximum total supply
- The gas cost of transfers
Correct answer: Only the display formatting of token amounts off-chain
decimals() is purely informational for UI display; the contract stores integer values regardless.
Question 4: Which event must an ERC-20 token emit when tokens move between addresses?
- Transfer(from, to, value) (Correct answer)
- Approval(owner, spender, value)
- Sent(operator, from, to)
- Mint(to, value)
Correct answer: Transfer(from, to, value)
The Transfer event is required on every token movement, including minting (from the zero address).
Question 5: Why is it best practice to emit a Transfer event from the zero address when minting ERC-20 tokens?
- So off-chain indexers can track supply changes consistently (Correct answer)
- Because the EVM rejects mints without it
- To reduce gas costs
- To prevent reentrancy
Correct answer: So off-chain indexers can track supply changes consistently
Emitting Transfer from address(0) lets explorers and indexers treat minting as a standard balance change.
Question 6: What problem does the ERC-2612 'permit' extension solve for ERC-20 tokens?
- It allows gasless approvals via off-chain signed messages (Correct answer)
- It increases the maximum supply
- It adds NFT metadata
- It enables cross-chain bridging automatically
Correct answer: It allows gasless approvals via off-chain signed messages
ERC-2612 permit lets users approve spenders with a signature, removing the need for a separate approve transaction.
Question 7: If an ERC-20 transfer() returns false instead of reverting, what is the recommended way to handle it safely in a calling contract?
- Use a SafeERC20 wrapper that checks the return value and reverts on failure (Correct answer)
- Ignore the return value since transfers always succeed
- Retry the transfer in a loop
- Call selfdestruct on failure
Correct answer: Use a SafeERC20 wrapper that checks the return value and reverts on failure
SafeERC20 wrappers verify the boolean return and revert, handling non-compliant tokens correctly.
Which ERC-20 function returns the number of tokens a spender is still allowed to withdraw from an owner's account?