ERC-20 is a set of rules that Ethereum tokens follow to work well with wallets and exchanges. It defines how tokens can be transferred and how to keep track of balances.
Click to reveal answer
beginner
Name two required functions in an ERC-20 token contract.
The two required functions are transfer(address to, uint256 amount) to send tokens, and balanceOf(address owner) to check how many tokens an address has.
Click to reveal answer
intermediate
What does the approve function do in ERC-20?
It lets a token owner allow another address to spend tokens on their behalf, up to a set limit.
Click to reveal answer
intermediate
Why is the Transfer event important in ERC-20 tokens?
It helps wallets and apps track token movements by listening to these events, so users see updated balances.
Click to reveal answer
beginner
What is the purpose of the allowance function?
It shows how many tokens an owner allowed a spender to use. This helps control spending limits.
Click to reveal answer
Which function transfers tokens from the caller to another address?
AbalanceOf
Bapprove
Callowance
Dtransfer
✗ Incorrect
The transfer function sends tokens from the caller to a specified address.
What does the approve function allow?
AAllow another address to spend tokens
BCheck token balance
CTransfer tokens directly
DDestroy tokens
✗ Incorrect
approve lets a token owner give permission to another address to spend tokens.
Which event signals that tokens have moved between addresses?
AApproval
BMint
CTransfer
DBurn
✗ Incorrect
The Transfer event is emitted when tokens move from one address to another.
What does the allowance function return?
ATotal token supply
BTokens approved for spending by a spender
CBalance of an address
DNumber of transfers made
✗ Incorrect
allowance shows how many tokens a spender is allowed to use from an owner.
Which of these is NOT part of the ERC-20 standard?
Amint
BbalanceOf
Ctransfer
Dapprove
✗ Incorrect
mint is not required by ERC-20; it is an optional function for creating new tokens.
Explain the main functions and events that an ERC-20 token contract must have.
Think about how tokens move, how balances are checked, and how spending permissions work.
You got /6 concepts.
Describe how the approve and transferFrom functions work together in ERC-20 tokens.
Consider the roles of owner and spender in token transfers.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the balanceOf function in an ERC-20 token contract?
easy
A. To approve another address to spend tokens
B. To transfer tokens from one address to another
C. To check the token balance of a specific address
D. To mint new tokens to an address
Solution
Step 1: Understand the role of balanceOf
The balanceOf function returns how many tokens a given address owns.
Step 2: Compare with other functions
Functions like transfer move tokens, approve allows spending, and minting creates tokens. These are different from checking balance.
Final Answer:
To check the token balance of a specific address -> Option C
Quick Check:
balanceOf = check balance [OK]
Hint: balanceOf always returns token count for an address [OK]
Common Mistakes:
Confusing balanceOf with transfer function
Thinking approve checks balances
Mixing minting with balance checking
2. Which of the following is the correct Solidity function signature for transferring tokens in an ERC-20 contract?
easy
A. function transfer(address to, uint256 amount) public returns (bool);
B. function transfer(uint256 amount, address to) public returns (bool);
C. function transfer(address to) public returns (uint256);
D. function transfer(address from, address to, uint256 amount) public;
Solution
Step 1: Recall ERC-20 transfer signature
The standard transfer function takes the recipient address first, then the amount, and returns a boolean.
Step 2: Check each option
function transfer(address to, uint256 amount) public returns (bool); matches the standard: transfer(address to, uint256 amount) public returns (bool). Others have wrong parameter order, missing return, or extra parameters.
Final Answer:
function transfer(address to, uint256 amount) public returns (bool); -> Option A
Quick Check:
transfer(to, amount) returns bool [OK]
Hint: transfer always has (address to, uint256 amount) and returns bool [OK]
Common Mistakes:
Swapping parameter order
Omitting return type
Adding extra parameters not in standard
3. Given this snippet from an ERC-20 contract:
mapping(address => uint256) balances;
function transfer(address to, uint256 amount) public returns (bool) {
if (balances[msg.sender] >= amount) {
balances[msg.sender] -= amount;
balances[to] += amount;
return true;
}
return false;
}
What will transfer return if msg.sender has 50 tokens and tries to send 60 tokens?
medium
A. true
B. Returns the remaining balance
C. Throws an error
D. false
Solution
Step 1: Check balance condition
The function checks if balances[msg.sender] is at least amount. Here, 50 < 60, so condition fails.
Step 2: Determine function return
Since condition fails, the function skips token transfer and returns false.
Final Answer:
false -> Option D
Quick Check:
Insufficient balance returns false [OK]
Hint: Transfer returns false if sender lacks enough tokens [OK]
Common Mistakes:
Assuming transfer throws error on insufficient balance
Thinking it returns true anyway
Confusing return value with balance amount
4. Identify the bug in this ERC-20 approve function snippet:
B. Should emit an Approval event after setting allowance
C. Should check if amount is less than balance
D. Should decrease allowance instead of setting it
Solution
Step 1: Review ERC-20 approve requirements
The standard requires emitting an Approval event after changing allowance for transparency.
Step 2: Check function code
The function sets allowance but does not emit the Approval event, missing a key part of the standard.
Final Answer:
Should emit an Approval event after setting allowance -> Option B
Quick Check:
approve must emit Approval event [OK]
Hint: approve must emit Approval event to follow standard [OK]
Common Mistakes:
Ignoring event emission
Checking balance in approve (not required)
Decreasing allowance instead of setting
5. You want to add a feature to your ERC-20 token that prevents transfers when the contract is paused. Which is the best way to implement this without breaking the ERC-20 standard?
hard
A. Add a paused boolean and require it false in transfer and transferFrom functions
B. Remove the transfer function and replace it with a new function that checks pause
C. Add a new function pauseTransfer that users must call before transferring
D. Modify the balanceOf function to return zero when paused
Solution
Step 1: Understand pause feature integration
To pause transfers, the contract needs a state variable like paused and checks in transfer functions.
Step 2: Check ERC-20 compliance
Removing or renaming transfer breaks the standard. Changing balanceOf output breaks expected behavior. Adding a separate function for pause is not standard.
Final Answer:
Add a paused boolean and require it false in transfer and transferFrom functions -> Option A
Quick Check:
Pause by require(!paused) in transfer functions [OK]
Hint: Use a paused flag and require it false in transfer methods [OK]
Common Mistakes:
Removing or renaming standard functions
Changing balanceOf behavior
Adding extra steps users must call
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.