0
0
Blockchain / Solidityprogramming~10 mins

Event filtering in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to filter events by their name.

Blockchain / Solidity
const filteredEvents = events.filter(event => event.[1] === 'Transfer');
Drag options to blanks, or click blank then click option'
Atype
Btopic
CeventName
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name like 'type' or 'topic' which does not hold the event name.
2fill in blank
medium

Complete the code to filter events emitted by a specific address.

Blockchain / Solidity
const filteredEvents = events.filter(event => event.[1] === '0x1234abcd');
Drag options to blanks, or click blank then click option'
Asender
Bfrom
Caddress
Demitter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'address' or 'emitter' which may not be the correct property in the event object.
3fill in blank
hard

Fix the error in the code to filter events with a value greater than 1000.

Blockchain / Solidity
const bigValueEvents = events.filter(event => event.value [1] 1000);
Drag options to blanks, or click blank then click option'
A>
B==
C<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '>' causes syntax or logic errors.
Using '==' checks equality, not greater than.
4fill in blank
hard

Fill both blanks to filter events with a topic matching '0xabc' and a block number greater than 5000.

Blockchain / Solidity
const filtered = events.filter(event => event.[1] === '0xabc' && event.[2] > 5000);
Drag options to blanks, or click blank then click option'
Atopic
BblockNumber
Cblock
Dhash
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'block' instead of 'blockNumber' which may not exist.
Using 'hash' which is unrelated to topic or block number.
5fill in blank
hard

Fill all three blanks to create a dictionary of event counts by event name, filtering only events with value greater than 10.

Blockchain / Solidity
const eventCounts = events.reduce((acc, event) => {
  if (event.[1] > 10) {
    acc[event.[2]] = (acc[event.[3]] || 0) + 1;
  }
  return acc;
}, {});
Drag options to blanks, or click blank then click option'
Avalue
Bname
Dtopic
Attempts:
3 left
💡 Hint
Common Mistakes
Using different properties for counting keys causes incorrect counts.
Checking wrong property for value filtering.