0
0
Blockchain / Solidityprogramming~10 mins

Why events communicate contract activity in Blockchain / Solidity - Test Your Understanding

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

Complete the code to declare an event named Transfer.

Blockchain / Solidity
event [1](address indexed from, address indexed to, uint256 value);
Drag options to blanks, or click blank then click option'
ATransfer
BSend
CReceive
DNotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-standard event name that won't be recognized by tools.
2fill in blank
medium

Complete the code to emit the Transfer event when tokens move.

Blockchain / Solidity
emit [1](msg.sender, recipient, amount);
Drag options to blanks, or click blank then click option'
ASend
BReceive
CNotify
DTransfer
Attempts:
3 left
💡 Hint
Common Mistakes
Using emit with an event name that was not declared.
3fill in blank
hard

Fix the error in the event declaration to index the 'to' address.

Blockchain / Solidity
event Transfer(address indexed from, [1] address to, uint256 value);
Drag options to blanks, or click blank then click option'
Aindexed
Bpublic
Cpayable
Dmemory
Attempts:
3 left
💡 Hint
Common Mistakes
Using visibility keywords like 'public' or 'payable' in event parameters.
4fill in blank
hard

Fill both blanks to complete the event emission with correct parameters.

Blockchain / Solidity
emit Transfer([1], [2], amount);
Drag options to blanks, or click blank then click option'
Amsg.sender
Brecipient
Cowner
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping sender and recipient addresses.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps addresses to balances greater than zero.

Blockchain / Solidity
mapping(address => uint256) public balances;

function getActiveBalances() public view returns (address[] memory) {
    address[] memory active;
    uint count = 0;
    for (uint i = 0; i < [1]; i++) {
        address user = users[i];
        if (balances[user] [2] 0) {
            active[count] = user;
            count [3] 1;
        }
    }
    return active;
}
Drag options to blanks, or click blank then click option'
Ausers.length
B>
C+=
Dbalances.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect loop length or wrong comparison operator.