0
0
Blockchain / Solidityprogramming~10 mins

Listening to events on 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 to the 'Transfer' event from a smart contract.

Blockchain / Solidity
contract.on('Transfer', (from, to, amount) => {
  console.log('Transfer from', from, 'to', to, 'amount', [1]);
});
Drag options to blanks, or click blank then click option'
Aamount
Bto
Cfrom
Devent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to' or 'from' instead of 'amount' to log the transfer value.
2fill in blank
medium

Complete the code to stop listening to the 'Approval' event.

Blockchain / Solidity
contract.[1]('Approval');
Drag options to blanks, or click blank then click option'
AremoveAllListeners
Bon
Clisten
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'removeAllListeners' to stop listening.
3fill in blank
hard

Fix the error in the code to correctly listen to the 'Deposit' event and log the amount.

Blockchain / Solidity
contract.on('Deposit', (user, amount) => {
  console.log('User deposited:', [1]);
});
Drag options to blanks, or click blank then click option'
Adeposit
Buser
Cevent
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Logging 'user' instead of 'amount' for the deposit value.
4fill in blank
hard

Fill both blanks to create a filter for the 'Transfer' event where the sender is a specific address.

Blockchain / Solidity
const filter = contract.filters.Transfer([1], [2]);
Drag options to blanks, or click blank then click option'
A'0x1234567890abcdef1234567890abcdef12345678'
Bnull
C'0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'undefined' or a wrong address in the blanks.
5fill in blank
hard

Fill all three blanks to listen to the 'Approval' event, filter by owner address, and log the spender and value.

Blockchain / Solidity
const filter = contract.filters.Approval([1], null);

contract.on(filter, (owner, spender, value) => {
  console.log('Spender:', [2], 'Value:', [3]);
});
Drag options to blanks, or click blank then click option'
A'0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
Bspender
Cvalue
D'0x1234567890abcdef1234567890abcdef12345678'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up owner and spender addresses or logging wrong variables.