0
0
Blockchain / Solidityprogramming~10 mins

Emitting events 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 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
BLog
CSend
DNotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like Log or Notify instead of Transfer.
Forgetting to declare the event.
2fill in blank
medium

Complete the code to emit the Transfer event when tokens are sent.

Blockchain / Solidity
emit Transfer([1], to, amount);
Drag options to blanks, or click blank then click option'
Amsg.sender
Baddress(this)
Cowner
Drecipient
Attempts:
3 left
💡 Hint
Common Mistakes
Using owner or recipient which may not be defined.
Using address(this) which refers to the contract itself.
3fill in blank
hard

Fix the error in the event emission code to correctly emit the Approval event.

Blockchain / Solidity
emit Approval(owner, [1], amount);
Drag options to blanks, or click blank then click option'
Amsg.sender
Brecipient
Cspender
Dto
Attempts:
3 left
💡 Hint
Common Mistakes
Using recipient or to which are not correct for Approval.
Using msg.sender which may not be the spender.
4fill in blank
hard

Fill both blanks to declare and emit a custom event named Deposit with an indexed sender and amount.

Blockchain / Solidity
event [1](address indexed sender, uint256 amount);

function deposit() public payable {
    emit [2](msg.sender, msg.value);
}
Drag options to blanks, or click blank then click option'
ADeposit
BTransfer
CApproval
DWithdraw
Attempts:
3 left
💡 Hint
Common Mistakes
Using different event names in declaration and emission.
Using standard event names like Transfer instead of Deposit.
5fill in blank
hard

Fill all three blanks to declare an event named OwnershipTransferred and emit it with previous and new owner addresses.

Blockchain / Solidity
event [1](address indexed [2], address indexed [3]);

function transferOwnership(address newOwner) public {
    address oldOwner = owner;
    owner = newOwner;
    emit OwnershipTransferred(oldOwner, newOwner);
}
Drag options to blanks, or click blank then click option'
AOwnershipTransferred
BpreviousOwner
CnewOwner
Downer
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like owner instead of previousOwner.
Mismatching event name and emission.