0
0
Blockchain / Solidityprogramming~20 mins

Indexed parameters in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Indexed Parameters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of event with indexed parameters
Consider the following Solidity event and transaction. What will be the output when the event is emitted and filtered by the indexed parameter?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract Test {
    event Transfer(address indexed from, address indexed to, uint amount);

    function send(address to, uint amount) public {
        emit Transfer(msg.sender, to, amount);
    }
}
AThe event logs will not include any indexed parameters as topics.
BThe event logs will include data for 'from', 'to', and 'amount' but no topics.
CThe event logs will include only the 'amount' as a topic and 'from' and 'to' as data.
DThe event logs will include topics for 'from' and 'to' addresses and data for 'amount'.
Attempts:
2 left
💡 Hint
Indexed parameters appear as topics in event logs.
Predict Output
intermediate
1:30remaining
Number of topics in event logs
Given this Solidity event, how many topics will be present in the event log when emitted?
Blockchain / Solidity
event Approval(address indexed owner, address indexed spender, uint256 value);
A3 topics: one for the event signature and two for the indexed parameters.
B2 topics: one for the event signature and one for all indexed parameters combined.
C1 topic: only the event signature is a topic.
D4 topics: one for the event signature and three for each parameter.
Attempts:
2 left
💡 Hint
Each indexed parameter adds one topic, plus the event signature topic.
🔧 Debug
advanced
2:30remaining
Why does filtering by a non-indexed parameter fail?
A developer tries to filter events by a non-indexed parameter but gets no results. Why does this happen?
Blockchain / Solidity
event Deposit(address indexed user, uint amount);

// Filtering by amount
filter = {amount: 100};
ABecause the amount parameter is indexed but the filter syntax is wrong.
BBecause non-indexed parameters are stored in data, not topics, and cannot be filtered by the Ethereum node.
CBecause the event signature is missing from the filter.
DBecause the event was not emitted properly.
Attempts:
2 left
💡 Hint
Filtering by indexed parameters uses topics, non-indexed parameters are in data and not filterable.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in event declaration
Which option contains a syntax error in declaring an event with indexed parameters?
Aevent Log(address sender indexed, uint value);
Bevent Log(address indexed sender, uint indexed value);
Cevent Log(address indexed sender, uint value);
Devent Log(address sender, uint indexed value);
Attempts:
2 left
💡 Hint
The 'indexed' keyword must come immediately after the type.
🚀 Application
expert
3:00remaining
Max number of indexed parameters in an event
What is the maximum number of indexed parameters allowed in a Solidity event, and why?
A2 indexed parameters, because only two topics are reserved for parameters.
B4 indexed parameters, because there is no limit on indexed parameters.
C3 indexed parameters, because the Ethereum log topics limit is 4 including the event signature.
D5 indexed parameters, because the EVM supports up to 5 topics per event.
Attempts:
2 left
💡 Hint
The event signature occupies one topic, and the total topics per log is limited.