Bird
Raised Fist0
Blockchain / Solidityprogramming~5 mins

ERC-20 fungible token standard in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the ERC-20 standard in blockchain?
ERC-20 is a technical standard used for smart contracts on the Ethereum blockchain to create fungible tokens. It defines a common set of rules that all tokens must follow to be compatible with wallets and exchanges.
Click to reveal answer
beginner
Name three mandatory functions defined by the ERC-20 standard.
The three mandatory functions are:
1. totalSupply() - returns total tokens.
2. balanceOf(address) - returns token balance of an address.
3. transfer(address, uint256) - transfers tokens to another address.
Click to reveal answer
intermediate
What is the purpose of the approve and transferFrom functions in ERC-20?
<code>approve</code> allows an owner to let another address spend tokens on their behalf. <code>transferFrom</code> lets the approved address transfer tokens from the owner's account. This enables delegated transfers.
Click to reveal answer
beginner
What event does an ERC-20 token emit when tokens are transferred?
The Transfer event is emitted. It logs the sender address, receiver address, and the amount of tokens transferred. This helps wallets and apps track token movements.
Click to reveal answer
beginner
Why is the ERC-20 standard important for token interoperability?
Because all ERC-20 tokens follow the same rules, wallets, exchanges, and other tools can work with any ERC-20 token without special changes. This makes tokens easy to use and trade.
Click to reveal answer
Which function returns the total number of tokens in an ERC-20 contract?
AtotalSupply()
BbalanceOf()
Ctransfer()
Dapprove()
What does the transfer function do in ERC-20?
AReturns token balance
BTransfers tokens from one address to another
CApproves spending allowance
DCreates new tokens
Which event is emitted when tokens are transferred in ERC-20?
ABurn
BApproval
CMint
DTransfer
What is the role of the approve function?
ATo transfer tokens directly
BTo check total supply
CTo allow another address to spend tokens on your behalf
DTo burn tokens
Why do ERC-20 tokens follow a standard?
ATo ensure all tokens work with wallets and exchanges easily
BTo limit token supply
CTo prevent token transfers
DTo make tokens unique and incompatible
Explain the key functions and events defined in the ERC-20 standard and their roles.
Think about how tokens are counted, moved, and delegated.
You got /5 concepts.
    Describe why the ERC-20 standard is important for token usability and interoperability in the Ethereum ecosystem.
    Consider how different tokens can work together smoothly.
    You got /4 concepts.

      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