0
0
Blockchain / Solidityprogramming~10 mins

Listening to events (frontend) 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 listen for the 'Transfer' event on a contract.

Blockchain / Solidity
contract.on('[1]', (from, to, amount) => {
  console.log(`Transfer from ${from} to ${to} of ${amount}`);
});
Drag options to blanks, or click blank then click option'
ATransfer
BApproval
CDeposit
DWithdraw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong event name like 'Approval' instead of 'Transfer'.
Forgetting to put the event name as a string.
2fill in blank
medium

Complete the code to remove the event listener for 'Transfer'.

Blockchain / Solidity
contract.[1]('Transfer', callbackFunction);
Drag options to blanks, or click blank then click option'
Alisten
Boff
CremoveListener
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'off' which may not be supported in some libraries.
Using 'listen' which is not a valid method.
3fill in blank
hard

Fix the error in the code to correctly listen for events with filters.

Blockchain / Solidity
const filter = contract.filters.[1](null, userAddress);
contract.on(filter, (from, to, amount) => {
  console.log(`Filtered transfer from ${from} to ${to} of ${amount}`);
});
Drag options to blanks, or click blank then click option'
AApproval
BTransfer
CDeposit
DWithdraw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong event name in the filter.
Passing incorrect parameters to the filter method.
4fill in blank
hard

Fill both blanks to create a filter for 'Approval' events where the owner is a specific address.

Blockchain / Solidity
const filter = contract.filters.[1]([2], null);
Drag options to blanks, or click blank then click option'
AApproval
B0x1234567890abcdef1234567890abcdef12345678
CTransfer
D0xabcdefabcdefabcdefabcdefabcdefabcdefabcd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Transfer' instead of 'Approval' for the event name.
Using the wrong address or null in the filter parameters.
5fill in blank
hard

Fill all three blanks to listen for 'Deposit' events and log the depositor and amount.

Blockchain / Solidity
contract.on('[1]', ([2], [3]) => {
  console.log(`Deposit by ${depositor} of ${amount}`);
});
Drag options to blanks, or click blank then click option'
ADeposit
Bdepositor
Camount
Dwithdrawer
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event name like 'Withdraw'.
Using incorrect parameter names that don't match the event.