Challenge - 5 Problems
ERC-20 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Remember the transfer function moves tokens from the sender to the receiver and emits an event with those details.
✗ Incorrect
The transfer function deducts the amount from the sender's balance and adds it to the receiver's balance. It then emits a Transfer event with the sender as 'from', the receiver as 'to', and the amount transferred as 'value'.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about the function that moves tokens from one account to another by a third party.
✗ Incorrect
The
transferFrom function allows a spender who has been approved by the token owner to transfer tokens from the owner's account to another account.🔧 Debug
advanced2: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);
Attempts:
2 left
💡 Hint
Consider what happens if the spender uses the old allowance before the new one is set.
✗ Incorrect
This approve implementation is vulnerable to the known ERC-20 race condition where a spender can use the old allowance and the new allowance if the owner changes it without first setting it to zero.
📝 Syntax
advanced1: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.
Attempts:
2 left
💡 Hint
The ERC-20 standard requires the first two parameters to be indexed for filtering.
✗ Incorrect
The Transfer event must have the 'from' and 'to' parameters indexed to allow efficient filtering in logs. Option B correctly uses 'indexed' for both.
🚀 Application
expert3: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);
Attempts:
2 left
💡 Hint
Add minted tokens to total supply and subtract burned tokens.
✗ Incorrect
Starting with 1000 tokens, minting 500 increases total supply to 1500. Burning 200 reduces total supply to 1300.