0
0
Blockchain / Solidityprogramming~10 mins

Event-driven architecture patterns 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 emit an event named 'Transfer' in a smart contract.

Blockchain / Solidity
emit [1](msg.sender, recipient, amount);
Drag options to blanks, or click blank then click option'
ATransfer
BSend
CNotify
DEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong event name causes a compilation error.
2fill in blank
medium

Complete the code to listen for the 'Approval' event in a blockchain client.

Blockchain / Solidity
contractInstance.events.[1]({}, (error, event) => { console.log(event); });
Drag options to blanks, or click blank then click option'
ADeposit
BTransfer
CApproval
DWithdraw
Attempts:
3 left
💡 Hint
Common Mistakes
Listening to a wrong event name results in no events captured.
3fill in blank
hard

Fix the error in the event filter to only get events where 'from' equals the sender address.

Blockchain / Solidity
contractInstance.getPastEvents('Transfer', { filter: { [1]: senderAddress } });
Drag options to blanks, or click blank then click option'
Aamount
Bfrom
Cto
Drecipient
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to' or 'recipient' filters the wrong address field.
4fill in blank
hard

Fill both blanks to create a subscription that listens for 'Deposit' events and logs the amount.

Blockchain / Solidity
subscription = contract.events.[1]().on('[2]', (event) => { console.log(event.returnValues.amount); });
Drag options to blanks, or click blank then click option'
ADeposit
BTransfer
Cdata
Dchanged
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event name or event type causes no logs.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps event names to their handler functions if the event name starts with 'On'.

Blockchain / Solidity
handlers = { [1]: [2] for [3] in eventList if [1].startswith('On') }
Drag options to blanks, or click blank then click option'
Aevent
Bhandle_event
Dhandler
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using wrong function names.