What is the main purpose of events in smart contracts?
Events are used to communicate contract activity to external listeners, such as user interfaces or other off-chain systems, by logging important information when certain actions happen inside the contract.
Click to reveal answer
intermediate
How do events help reduce blockchain data usage?
Events store data in transaction logs instead of contract storage, which is cheaper and more efficient, allowing external apps to track contract activity without increasing on-chain storage costs.
Click to reveal answer
beginner
Why can't smart contracts directly notify external systems without events?
Smart contracts run on the blockchain and cannot push messages outside themselves; events act as signals that external systems can watch for to know when something important happened.
Click to reveal answer
intermediate
What is the difference between contract storage and event logs?
Contract storage holds persistent data on-chain and costs more gas, while event logs are cheaper, temporary records used to notify external listeners about contract actions.
Click to reveal answer
beginner
How do events improve user experience in decentralized applications (dApps)?
Events allow dApps to listen for contract changes and update the user interface in real-time, making interactions smoother and more responsive without constant polling.
Click to reveal answer
What do events in smart contracts primarily do?
ALog contract activity for external systems
BStore permanent data on the blockchain
CExecute contract functions
DSend cryptocurrency to users
✗ Incorrect
Events log contract activity so external systems can detect and respond to changes.
Why are events preferred over contract storage for notifying external apps?
AEvents are cheaper and more efficient to store
BEvents can execute code faster
CContract storage is not accessible
DEvents increase gas costs
✗ Incorrect
Events use transaction logs which cost less gas than storing data in contract storage.
Which of the following is NOT true about events?
AThey are recorded in transaction logs
BThey help external apps track contract activity
CThey allow smart contracts to push messages directly to users
DThey reduce the need for constant polling
✗ Incorrect
Smart contracts cannot push messages directly; events only log information for external listeners.
How do events improve decentralized app responsiveness?
ABy reducing blockchain size
BBy storing user data permanently
CBy increasing transaction speed
DBy enabling real-time updates from contract activity
✗ Incorrect
Events let dApps listen and update interfaces immediately when contract actions occur.
Where are event logs stored?
AIn contract storage variables
BIn transaction logs on the blockchain
COff-chain databases only
DIn user wallets
✗ Incorrect
Event logs are stored in the blockchain's transaction logs, accessible to external systems.
Explain why events are essential for communicating smart contract activity to external systems.
Think about how apps know what happens inside a contract.
You got /4 concepts.
Describe the difference between contract storage and event logs and why events are used for notifications.
Consider cost and purpose of each.
You got /4 concepts.
Practice
(1/5)
1. Why do smart contracts use events to communicate activity?
easy
A. To send messages about contract actions to external listeners
B. To store large amounts of data permanently on the blockchain
C. To increase the gas cost of contract execution
D. To prevent users from interacting with the contract
Solution
Step 1: Understand the purpose of events in smart contracts
Events are designed to notify external systems about what happens inside the contract without storing data permanently on-chain.
Step 2: Identify the correct use of events
Events send messages to external listeners, like user interfaces or monitoring tools, about contract actions.
Final Answer:
To send messages about contract actions to external listeners -> Option A
Quick Check:
Events notify external systems = C [OK]
Hint: Events notify outside world about contract actions [OK]
Common Mistakes:
Thinking events store large data permanently
Believing events increase gas cost unnecessarily
Confusing events with access control mechanisms
2. Which of the following is the correct syntax to declare an event in Solidity?
easy
A. event Transfer function(address from, address to, uint amount);
B. event Transfer(address indexed from, address indexed to, uint amount);
C. event Transfer {address from, address to, uint amount};
D. event Transfer = (address from, address to, uint amount);
Solution
Step 1: Recall Solidity event declaration syntax
Events are declared with the keyword 'event', followed by the event name and parameters in parentheses, ending with a semicolon.
Step 2: Identify the correct syntax among options
event Transfer(address indexed from, address indexed to, uint amount); matches the correct Solidity syntax with 'indexed' keywords for filtering.
Final Answer:
event Transfer(address indexed from, address indexed to, uint amount); -> Option B
Quick Check:
Correct event syntax uses parentheses and semicolon = D [OK]
Hint: Events use 'event Name(params);' syntax in Solidity [OK]
Common Mistakes:
Using '=' instead of parentheses
Using curly braces instead of parentheses
Adding 'function' keyword in event declaration
3. Given the Solidity event and function below, what will be emitted when transfer(0x123, 100) is called?
event Transfer(address indexed from, address indexed to, uint amount);
function transfer(address to, uint amount) public {
emit Transfer(msg.sender, to, amount);
}
medium
A. No event emitted because emit keyword is missing
B. Transfer event with from = 0x123, to = caller address, amount = 100
C. Transfer event with from = caller address, to = 0x123, amount = 100
D. Transfer event with from = 0x0, to = 0x123, amount = 0
Solution
Step 1: Understand the function call and event emission
The function emits a Transfer event with 'msg.sender' as 'from', 'to' as the passed address, and 'amount' as passed.
Step 2: Apply the call parameters
Calling transfer(0x123, 100) sets 'to' to 0x123 and 'amount' to 100; 'msg.sender' is the caller's address.
Final Answer:
Transfer event with from = caller address, to = 0x123, amount = 100 -> Option C
Quick Check:
emit Transfer(msg.sender, to, amount) = A [OK]
Hint: emit uses caller as from, passed args as to and amount [OK]
Common Mistakes:
Confusing 'from' and 'to' parameters
Forgetting 'emit' keyword
Assuming default zero addresses
4. Identify the error in the following Solidity code snippet that prevents the event from being emitted:
event Deposit(address indexed sender, uint amount);
function deposit(uint amount) public {
Deposit(msg.sender, amount);
}
medium
A. Event parameters are in wrong order
B. Function must be marked as 'payable' to emit events
C. Event name should be lowercase
D. Missing 'emit' keyword before the event call
Solution
Step 1: Review event emission syntax in Solidity
Since Solidity 0.4.21, events must be emitted using the 'emit' keyword.
Step 2: Check the code for missing 'emit'
The code calls 'Deposit(msg.sender, amount);' without 'emit', so the event won't be emitted.
Final Answer:
Missing 'emit' keyword before the event call -> Option D
Quick Check:
Events require 'emit' keyword = B [OK]
Hint: Always use 'emit' before event calls in Solidity [OK]
Common Mistakes:
Omitting 'emit' keyword
Assuming event names are case-insensitive
Thinking 'payable' is required for events
5. You want to track token transfers in your contract efficiently. Which approach best uses events to minimize gas costs and allow external monitoring?
hard
A. Emit an event with indexed sender and receiver addresses and the amount transferred
B. Store all transfer details in a public array inside the contract
C. Use a mapping to save transfer history and emit no events
D. Emit events without indexed parameters to save gas
Solution
Step 1: Understand gas cost and event indexing
Indexed event parameters allow efficient filtering by external tools and cost less gas than storing data on-chain.
Step 2: Evaluate options for tracking transfers
Emitting events with indexed sender and receiver is efficient and allows external monitoring without high storage costs.
Final Answer:
Emit an event with indexed sender and receiver addresses and the amount transferred -> Option A
Quick Check:
Indexed events minimize gas and enable monitoring = A [OK]
Hint: Use indexed event params for efficient tracking [OK]
Common Mistakes:
Storing all data on-chain increases gas costs
Not indexing event parameters reduces filtering ability
Avoiding events leads to poor external monitoring
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.