Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

ERC-20 fungible token standard in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ERC-20 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of the transfer function call?
Consider the following simplified ERC-20 transfer function call. What will be the value of the event log emitted after calling transfer(receiver, 50) from an account with 100 tokens?
Blockchain / Solidity
mapping(address => uint256) balances;

function transfer(address to, uint256 amount) public returns (bool) {
    require(balances[msg.sender] >= amount, "Insufficient balance");
    balances[msg.sender] -= amount;
    balances[to] += amount;
    emit Transfer(msg.sender, to, amount);
    return true;
}

// Initial balances:
balances[msg.sender] = 100;
balances[receiver] = 0;

// Call:
transfer(receiver, 50);
ATransfer event emitted with from=msg.sender, to=receiver, value=50
BTransfer event emitted with from=receiver, to=msg.sender, value=50
CTransfer event emitted with from=msg.sender, to=receiver, value=100
DNo event emitted due to insufficient balance
Attempts:
2 left
💡 Hint
Remember the transfer function moves tokens from the sender to the receiver and emits an event with those details.
🧠 Conceptual
intermediate
1:30remaining
Which function allows a third party to spend tokens on behalf of the owner?
In the ERC-20 standard, which function enables an approved spender to transfer tokens from the owner's account?
Atransfer
BbalanceOf
CtransferFrom
Dapprove
Attempts:
2 left
💡 Hint
Think about the function that moves tokens from one account to another by a third party.
🔧 Debug
advanced
2:30remaining
Identify the error in this approve function implementation
What error will occur when calling this approve function implementation?
Blockchain / Solidity
mapping(address => mapping(address => uint256)) allowances;

function approve(address spender, uint256 amount) public returns (bool) {
    allowances[msg.sender][spender] = amount;
    emit Approval(msg.sender, spender, amount);
    return true;
}

// Usage:
approve(spender, 100);
ANo error; function works correctly
BReentrancy vulnerability allowing double spending
CCompilation error due to missing return statement
DApproval race condition allowing spender to spend more than intended
Attempts:
2 left
💡 Hint
Consider what happens if the spender uses the old allowance before the new one is set.
📝 Syntax
advanced
1:30remaining
Which option correctly declares the Transfer event in Solidity?
Choose the correct Solidity syntax to declare the Transfer event as per ERC-20 standard.
Aevent Transfer(address from, address to, uint256 value);
Bevent Transfer(address indexed from, address indexed to, uint256 value);
Cevent Transfer(address indexed from, address to, uint256 value);
Devent Transfer(address from, address indexed to, uint256 value);
Attempts:
2 left
💡 Hint
The ERC-20 standard requires the first two parameters to be indexed for filtering.
🚀 Application
expert
3:00remaining
How many total tokens exist after minting and burning operations?
Given the following operations on an ERC-20 token contract, what is the total supply after these calls? 1. Initial total supply is 1000 tokens. 2. Mint 500 tokens to address A. 3. Burn 200 tokens from address B. Assume address B has at least 200 tokens before burning.
Blockchain / Solidity
uint256 totalSupply = 1000;

function mint(address to, uint256 amount) public {
    totalSupply += amount;
    balances[to] += amount;
}

function burn(address from, uint256 amount) public {
    require(balances[from] >= amount, "Insufficient balance to burn");
    balances[from] -= amount;
    totalSupply -= amount;
}

// Operations:
mint(addressA, 500);
burn(addressB, 200);
A1300 tokens
B1500 tokens
C1000 tokens
D800 tokens
Attempts:
2 left
💡 Hint
Add minted tokens to total supply and subtract burned tokens.

Practice

(1/5)
1. What is the main purpose of the ERC-20 standard in Ethereum?
easy
A. To ensure tokens have a common set of functions for compatibility
B. To create unique non-fungible tokens
C. To define the Ethereum network consensus rules
D. To manage smart contract deployment costs

Solution

  1. Step 1: Understand ERC-20 purpose

    ERC-20 defines a common interface for fungible tokens to work uniformly.
  2. Step 2: Identify the correct purpose

    This standard allows wallets and apps to interact with tokens easily by using the same functions.
  3. Final Answer:

    To ensure tokens have a common set of functions for compatibility -> Option A
  4. Quick Check:

    ERC-20 = Common token interface [OK]
Hint: ERC-20 standardizes token functions for easy use [OK]
Common Mistakes:
  • Confusing ERC-20 with NFT standards
  • Thinking ERC-20 controls Ethereum network rules
  • Assuming ERC-20 manages deployment costs
2. Which of the following is the correct function signature to check a token balance in ERC-20?
easy
A. function balanceOf(address owner) external view returns (uint256);
B. function getBalance(address owner) public returns (uint256);
C. function balance(address owner) external returns (bool);
D. function checkBalance(address owner) public view returns (bool);

Solution

  1. Step 1: Recall ERC-20 balance function

    The standard defines balanceOf as a view function returning a uint256 balance.
  2. Step 2: Match function signature

    function balanceOf(address owner) external view returns (uint256); matches the exact signature: external view returns (uint256).
  3. Final Answer:

    function balanceOf(address owner) external view returns (uint256); -> Option A
  4. Quick Check:

    balanceOf = correct signature [OK]
Hint: balanceOf returns uint256 and is a view function [OK]
Common Mistakes:
  • Using wrong function name like getBalance
  • Missing view keyword for read-only function
  • Returning bool instead of uint256
3. Given this Solidity snippet from an ERC-20 token contract:
function transfer(address to, uint256 amount) public returns (bool) {
    if (balances[msg.sender] < amount) {
        return false;
    }
    balances[msg.sender] -= amount;
    balances[to] += amount;
    emit Transfer(msg.sender, to, amount);
    return true;
}

What will transfer return if the sender has 50 tokens and tries to send 60 tokens?
medium
A. true
B. false
C. It will throw an error
D. It will return zero

Solution

  1. Step 1: Check sender balance condition

    The function checks if sender's balance is less than amount; if yes, returns false.
  2. Step 2: Apply given values

    Sender has 50 tokens but tries to send 60, so condition is true and function returns false.
  3. Final Answer:

    false -> Option B
  4. Quick Check:

    Insufficient balance returns false [OK]
Hint: Transfer returns false if balance is insufficient [OK]
Common Mistakes:
  • Assuming it throws error instead of returning false
  • Thinking it returns true regardless
  • Confusing return value with event emission
4. Identify the error in this ERC-20 approve function snippet:
function approve(address spender, uint256 amount) public returns (bool) {
    allowances[msg.sender][spender] = amount;
    emit Approval(msg.sender, spender, amount);
    return true;
}

What is the common security issue with this implementation?
medium
A. It does not emit the Approval event
B. It does not check if spender is zero address
C. It allows race condition by directly setting allowance
D. It returns false instead of true

Solution

  1. Step 1: Understand approve race condition

    Directly setting allowance can cause race conditions if spender uses old and new allowance simultaneously.
  2. Step 2: Identify missing mitigation

    Safe implementations require resetting allowance to zero before changing it to new value to avoid this issue.
  3. Final Answer:

    It allows race condition by directly setting allowance -> Option C
  4. Quick Check:

    approve race condition = direct allowance set [OK]
Hint: Always reset allowance to zero before changing it [OK]
Common Mistakes:
  • Thinking missing zero address check is main issue
  • Assuming Approval event is missing
  • Believing return value is incorrect
5. You want to create an ERC-20 token that charges a 1% fee on every transfer and sends it to a fee collector address. Which modification to the transfer function correctly implements this?
hard
A. Send full amount to recipient, then send 1% from sender to collector
B. Add 1% to amount, send full amount to recipient, send fee separately
C. Send full amount to recipient and fee collector equally
D. Deduct 1% from amount, send fee to collector, send rest to recipient

Solution

  1. Step 1: Calculate fee and net transfer

    Calculate 1% fee from amount, subtract it to get net amount to recipient.
  2. Step 2: Transfer fee and net amount correctly

    Send fee to fee collector address and net amount to recipient to implement fee deduction.
  3. Final Answer:

    Deduct 1% from amount, send fee to collector, send rest to recipient -> Option D
  4. Quick Check:

    Fee deducted and sent correctly = Deduct 1% from amount, send fee to collector, send rest to recipient [OK]
Hint: Subtract fee from amount before sending tokens [OK]
Common Mistakes:
  • Adding fee on top of amount instead of deducting
  • Sending full amount to recipient and fee separately from sender
  • Splitting amount equally between recipient and fee collector
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard