0
0
Blockchain / Solidityprogramming~20 mins

ERC-20 implementation in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 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 this simplified ERC-20 transfer function snippet:

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;
}

If balances[msg.sender] is 100 and amount is 50, what does transfer return?

Blockchain / Solidity
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;
}
AReturns the new balance of the sender
Bfalse
CReverts with 'Insufficient balance'
Dtrue
Attempts:
2 left
💡 Hint

Think about what the function returns after successfully transferring tokens.

🧠 Conceptual
intermediate
1:30remaining
Which event must an ERC-20 token emit on transfers?

In ERC-20 token contracts, which event is required to be emitted when tokens are transferred?

AApproval
BMint
CTransfer
DBurn
Attempts:
2 left
💡 Hint

Think about the event that signals token movement between addresses.

🔧 Debug
advanced
2:00remaining
What error does this approve function cause?

Examine this 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 error will this code cause when compiled?

Blockchain / Solidity
function approve(address spender, uint256 amount) public returns (bool) {
    allowances[msg.sender][spender] = amount;
    emit Approval(msg.sender, spender, amount);
    return true
}
ASyntaxError: Missing semicolon after return statement
BNo error, compiles successfully
CRuntimeError: Approval event not declared
DTypeError: allowances is not defined
Attempts:
2 left
💡 Hint

Check the end of the return statement carefully.

📝 Syntax
advanced
1:30remaining
Which option correctly declares the balances mapping?

In an ERC-20 contract, how do you correctly declare a mapping to store token balances?

Amapping(address => uint) balances() public;
Bmapping(address => uint) public balances;
Cmapping(address, uint) balances;
Dmapping(address => uint) balances;
Attempts:
2 left
💡 Hint

Remember the correct syntax for mappings and visibility keywords.

🚀 Application
expert
2:30remaining
What is the total supply after minting 1000 tokens?

Given this snippet of an ERC-20 token contract:

uint256 public totalSupply;

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

If totalSupply was initially 5000, what is its value after calling mint(0x123..., 1000)?

A6000
B1000
C5000
D0
Attempts:
2 left
💡 Hint

Think about how minting affects total supply.