Complete the code to listen to the 'Transfer' event from a smart contract.
contract.on('Transfer', (from, to, amount) => { console.log('Transfer from', from, 'to', to, 'amount', [1]); });
The 'amount' parameter holds the value transferred in the event. We log it to see the transfer amount.
Complete the code to stop listening to the 'Approval' event.
contract.[1]('Approval');
To stop listening to an event, we use 'removeAllListeners' with the event name.
Fix the error in the code to correctly listen to the 'Deposit' event and log the amount.
contract.on('Deposit', (user, amount) => { console.log('User deposited:', [1]); });
The 'amount' parameter holds the deposit value, so we log it to show how much was deposited.
Fill both blanks to create a filter for the 'Transfer' event where the sender is a specific address.
const filter = contract.filters.Transfer([1], [2]);
The first blank is the sender address to filter by. The second blank is 'null' to ignore the receiver address.
Fill all three blanks to listen to the 'Approval' event, filter by owner address, and log the spender and value.
const filter = contract.filters.Approval([1], null); contract.on(filter, (owner, spender, value) => { console.log('Spender:', [2], 'Value:', [3]); });
The first blank is the owner address to filter by. Then we log the 'spender' and 'value' parameters from the event.