0
0
Blockchain / Solidityprogramming~20 mins

Event filtering in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Event Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Solidity event filter code?

Consider the following Solidity code snippet that filters events by an indexed parameter:

pragma solidity ^0.8.0;

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

    function testFilter() public pure returns (string memory) {
        // Imagine filtering Transfer events where from == 0x123...
        // This is a conceptual example, not actual filtering code
        return "Filtered 3 events";
    }
}

What would be the output of testFilter() assuming it returns the count of filtered events?

A"Filtered 3 events"
B"Filtered 0 events"
C"Filtered all events"
D"Filtered 1 event"
Attempts:
2 left
💡 Hint

Look at the return statement inside testFilter().

🧠 Conceptual
intermediate
1:30remaining
Which indexed event parameter allows filtering by that parameter?

In Solidity events, which keyword allows a parameter to be used for filtering when listening to events?

Apublic
Bindexed
Cconstant
Dpayable
Attempts:
2 left
💡 Hint

It is a keyword placed before the parameter name in the event declaration.

Predict Output
advanced
2:30remaining
What error does this event filter code produce?

Given this JavaScript code using ethers.js to filter events:

const filter = contract.filters.Transfer(null, '0x0000000000000000000000000000000000000000');
const events = await contract.queryFilter(filter);
console.log(events.length);

What error will this code produce?

ANo error, prints number of events
BSyntaxError: unexpected token
CReferenceError: contract is not defined
DTypeError: invalid address
Attempts:
2 left
💡 Hint

Check if the address used is valid and the filter syntax is correct.

Predict Output
advanced
2:00remaining
What is the output of this Solidity event filtering example?

Consider this Solidity event and filter example:

pragma solidity ^0.8.0;

contract Example {
    event Data(uint indexed id, string value);

    function emitEvents() public {
        emit Data(1, "one");
        emit Data(2, "two");
        emit Data(3, "three");
    }

    // Conceptual filter: get events where id == 2
    function filterEvents() public pure returns (string memory) {
        return "Data with id 2: two";
    }
}

What does filterEvents() return?

A"Data with id 3: three"
B"Data with id 1: one"
C"Data with id 2: two"
D"No matching data"
Attempts:
2 left
💡 Hint

Look at the return statement in filterEvents().

🧠 Conceptual
expert
3:00remaining
Which option correctly describes event filtering in Ethereum logs?

Which statement correctly describes how event filtering works in Ethereum logs?

AFiltering requires decoding all contract storage to find events.
BFiltering scans all transaction input data to find matching events.
CFiltering is done by scanning block timestamps for event matches.
DFiltering uses indexed event parameters stored in topics to quickly find matching logs.
Attempts:
2 left
💡 Hint

Think about how Ethereum stores event data and how filters use topics.