Challenge - 5 Problems
Event Emission 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 Solidity event emission?
Consider the following Solidity contract snippet. What will be the output in the transaction logs after calling
setValue(42)?Blockchain / Solidity
pragma solidity ^0.8.0;
contract TestEvent {
event ValueChanged(address indexed author, uint oldValue, uint newValue);
uint public value;
function setValue(uint _value) public {
uint old = value;
value = _value;
emit ValueChanged(msg.sender, old, _value);
}
}Attempts:
2 left
💡 Hint
Remember that
msg.sender is the caller address and emit triggers the event.✗ Incorrect
The function sets the value from 0 to 42 and emits the event with the caller's address, old value 0, and new value 42.
🧠 Conceptual
intermediate1:30remaining
Why use indexed parameters in Solidity events?
In Solidity events, some parameters can be marked as
indexed. What is the main purpose of marking event parameters as indexed?Attempts:
2 left
💡 Hint
Think about how you can search for events in blockchain explorers.
✗ Incorrect
Indexed parameters allow clients to filter and search for events by those values efficiently.
🔧 Debug
advanced2:00remaining
What error does this Solidity event code produce?
Examine the following Solidity code snippet. What error will occur when compiling?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract EventTest {
event DataUpdated(uint indexed id, string indexed data);
function updateData(uint _id, string memory _data) public {
emit DataUpdated(_id, _data);
}
}Attempts:
2 left
💡 Hint
Check which types can be indexed in Solidity events.
✗ Incorrect
Solidity only allows value types and bytes32 to be indexed, not dynamic types like string.
❓ Predict Output
advanced1:30remaining
What is the number of topics in this emitted event?
Given the Solidity event and function below, how many topics will the emitted event have in the logs?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract TopicCount {
event MultiIndexed(address indexed sender, uint indexed id, string message);
function sendMessage(uint _id, string memory _msg) public {
emit MultiIndexed(msg.sender, _id, _msg);
}
}Attempts:
2 left
💡 Hint
Remember the event signature is always a topic, plus one topic per indexed parameter.
✗ Incorrect
The event signature is always a topic, and each indexed parameter adds one topic. Here, two parameters are indexed, so total topics are 3.
🚀 Application
expert2:30remaining
Which option produces the correct event log filtering in web3.js?
You want to listen for the
Transfer event from an ERC20 token contract filtering only transfers from address 0xabc.... Which web3.js code snippet correctly sets up this filter?Attempts:
2 left
💡 Hint
Check the correct property name for filtering event parameters in web3.js.
✗ Incorrect
The
filter object inside the event subscription specifies indexed parameters to filter by. Using filter: { from: '0xabc...' } filters events where the from parameter matches the address.