Challenge - 5 Problems
Event-Driven Blockchain Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this event handler code snippet?
Consider a blockchain smart contract that emits an event when a token is transferred. What will be the output of the following event listener code when a transfer event is emitted?
Blockchain / Solidity
contract Token {
event Transfer(address indexed from, address indexed to, uint amount);
function transfer(address to, uint amount) public {
emit Transfer(msg.sender, to, amount);
}
}
// Event listener pseudocode
Token.on('Transfer', (from, to, amount) => {
console.log(`Transfer from ${from} to ${to} of ${amount} tokens`);
});
// Simulate transfer
Token.transfer('0xABC', 100);Attempts:
2 left
💡 Hint
Remember that the 'from' address is the sender of the tokens, usually msg.sender.
✗ Incorrect
The event emits the sender's address as 'from', the recipient as 'to', and the amount transferred. The listener logs these values accordingly.
🧠 Conceptual
intermediate1:30remaining
Which pattern best describes decoupling components in blockchain event-driven systems?
In blockchain event-driven architecture, which pattern helps to decouple the smart contract logic from off-chain services by using events?
Attempts:
2 left
💡 Hint
Think about how listeners subscribe to events emitted by contracts.
✗ Incorrect
The Observer pattern allows off-chain services to listen to events emitted by smart contracts, enabling decoupling.
🔧 Debug
advanced2:00remaining
Identify the error in this event subscription code
This code subscribes to a blockchain event but does not receive any events. What is the error?
Blockchain / Solidity
contract Token {
event Approval(address indexed owner, address indexed spender, uint value);
}
// Subscription code
Token.on('approval', (owner, spender, value) => {
console.log(`Approved ${value} tokens from ${owner} to ${spender}`);
});Attempts:
2 left
💡 Hint
Check the exact event name spelling and casing.
✗ Incorrect
Event names in blockchain are case-sensitive. Using 'approval' instead of 'Approval' means no events are caught.
📝 Syntax
advanced1:30remaining
Which option correctly defines an event with multiple indexed parameters in Solidity?
Select the correct Solidity event declaration with two indexed parameters.
Attempts:
2 left
💡 Hint
Indexed keyword comes immediately after the type.
✗ Incorrect
In Solidity, 'indexed' must come after the type and before the parameter name.
🚀 Application
expert2:00remaining
How many events will be processed by the listener in this scenario?
A smart contract emits an event 'DataUpdated' every time data changes. The listener subscribes once and processes events from block 100 to 105. The contract emitted 'DataUpdated' events at blocks 101, 103, 103, 104, and 106. How many events will the listener process?
Attempts:
2 left
💡 Hint
Count only events emitted between blocks 100 and 105 inclusive.
✗ Incorrect
Events at blocks 101, 103 (two events), and 104 are within the range, totaling 4 events. The event at block 106 is outside the range.