Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Emitting events in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Event Emission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Solidity event emission?
Consider the following Solidity contract snippet. What will be the output in the transaction logs after calling setValue(42)?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract TestEvent {
    event ValueChanged(address indexed author, uint oldValue, uint newValue);
    uint public value;

    function setValue(uint _value) public {
        uint old = value;
        value = _value;
        emit ValueChanged(msg.sender, old, _value);
    }
}
AA compilation error due to missing event parameters
BAn event ValueChanged with author as zero address, oldValue 0, newValue 42
CAn event ValueChanged with author as caller address, oldValue 0, newValue 42
DNo event emitted because emit keyword is missing
Attempts:
2 left
💡 Hint
Remember that msg.sender is the caller address and emit triggers the event.
🧠 Conceptual
intermediate
1:30remaining
Why use indexed parameters in Solidity events?
In Solidity events, some parameters can be marked as indexed. What is the main purpose of marking event parameters as indexed?
ATo allow filtering of events by those parameters in the logs
BTo make the event parameters private and hidden from logs
CTo reduce gas cost by not storing those parameters
DTo automatically convert parameters to strings
Attempts:
2 left
💡 Hint
Think about how you can search for events in blockchain explorers.
🔧 Debug
advanced
2:00remaining
What error does this Solidity event code produce?
Examine the following Solidity code snippet. What error will occur when compiling?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract EventTest {
    event DataUpdated(uint indexed id, string indexed data);

    function updateData(uint _id, string memory _data) public {
        emit DataUpdated(_id, _data);
    }
}
ARuntime error: Event parameters mismatch
BCompilation error: Cannot index a string parameter
CNo error, code compiles and runs correctly
DCompilation error: Missing event declaration
Attempts:
2 left
💡 Hint
Check which types can be indexed in Solidity events.
❓ Predict Output
advanced
1:30remaining
What is the number of topics in this emitted event?
Given the Solidity event and function below, how many topics will the emitted event have in the logs?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract TopicCount {
    event MultiIndexed(address indexed sender, uint indexed id, string message);

    function sendMessage(uint _id, string memory _msg) public {
        emit MultiIndexed(msg.sender, _id, _msg);
    }
}
A3 topics: event signature + 2 indexed parameters
B2 topics: event signature + 1 indexed parameter
C1 topic: only event signature
D4 topics: event signature + 3 parameters
Attempts:
2 left
💡 Hint
Remember the event signature is always a topic, plus one topic per indexed parameter.
🚀 Application
expert
2:30remaining
Which option produces the correct event log filtering in web3.js?
You want to listen for the Transfer event from an ERC20 token contract filtering only transfers from address 0xabc.... Which web3.js code snippet correctly sets up this filter?
Acontract.events.Transfer({ from: '0xabc...' }, callback);
Bcontract.events.Transfer({ topics: ['0xabc...'] }, callback);
Ccontract.events.Transfer({ filter: { to: '0xabc...' } }, callback);
Dcontract.events.Transfer({ filter: { from: '0xabc...' } }, callback);
Attempts:
2 left
💡 Hint
Check the correct property name for filtering event parameters in web3.js.

Practice

(1/5)
1. What is the main purpose of emitting events in a blockchain smart contract?
easy
A. To send signals about important actions to external listeners
B. To store large amounts of data permanently on the blockchain
C. To execute complex calculations inside the contract
D. To create new tokens automatically

Solution

  1. Step 1: Understand event purpose

    Events are used to notify external systems about contract actions without heavy storage.
  2. Step 2: Compare options

    Only To send signals about important actions to external listeners describes sending signals to outside listeners, which matches event use.
  3. Final Answer:

    To send signals about important actions to external listeners -> Option A
  4. Quick Check:

    Events notify external listeners = D [OK]
Hint: Events notify outside world, not store big data [OK]
Common Mistakes:
  • Thinking events store large data permanently
  • Confusing events with token creation
  • Believing events run complex calculations
2. Which of the following is the correct syntax to emit an event named Transfer with parameters from, to, and amount in Solidity?
easy
A. event Transfer(from, to, amount);
B. Transfer.emit(from, to, amount);
C. emit Transfer(from, to, amount);
D. emit.Transfer(from, to, amount);

Solution

  1. Step 1: Recall Solidity event emission syntax

    In Solidity, events are emitted using the keyword emit followed by the event name and parameters in parentheses.
  2. Step 2: Check each option

    emit Transfer(from, to, amount); matches the correct syntax: emit Transfer(from, to, amount);. Others misuse dot notation or keywords.
  3. Final Answer:

    emit Transfer(from, to, amount); -> Option C
  4. Quick Check:

    emit keyword + event name + params = C [OK]
Hint: Use 'emit EventName(params);' exactly [OK]
Common Mistakes:
  • Using dot notation like emit.Transfer()
  • Writing event declaration instead of emission
  • Placing emit after event name
3. Given the Solidity code snippet:
event Deposit(address indexed sender, uint amount);

function deposit() public payable {
    emit Deposit(msg.sender, msg.value);
}

What happens when the deposit function is called with 1 ether?
medium
A. The function throws an error due to missing return
B. The contract balance decreases by 1 ether
C. No event is emitted because emit keyword is missing
D. An event Deposit is emitted with sender's address and amount 1 ether

Solution

  1. Step 1: Analyze the deposit function

    The function emits the Deposit event with the caller's address and the amount sent (msg.value).
  2. Step 2: Understand event emission effect

    Calling deposit with 1 ether triggers the event with sender and 1 ether amount; contract balance increases, no error.
  3. Final Answer:

    An event Deposit is emitted with sender's address and amount 1 ether -> Option D
  4. Quick Check:

    emit Deposit with sender and value = A [OK]
Hint: emit sends event with current call data [OK]
Common Mistakes:
  • Thinking contract balance decreases on deposit
  • Missing that emit keyword is present
  • Expecting return value in void function
4. Identify the error in this Solidity code snippet:
event Approval(address owner, address spender, uint amount);

function approve(address spender, uint amount) public {
    Approval(msg.sender, spender, amount);
}
medium
A. Missing the emit keyword before the event call
B. Event parameters are in wrong order
C. Function must be declared as view
D. Event name should be lowercase

Solution

  1. Step 1: Check event emission syntax

    In Solidity, events must be emitted using the emit keyword before calling the event.
  2. Step 2: Identify the error in code

    The code calls Approval(...) without emit, causing a syntax error.
  3. Final Answer:

    Missing the emit keyword before the event call -> Option A
  4. Quick Check:

    emit keyword required before event call = A [OK]
Hint: Always prefix event calls with 'emit' [OK]
Common Mistakes:
  • Omitting emit keyword
  • Assuming event names are case-insensitive
  • Thinking function needs view modifier
5. You want to track token transfers in your smart contract and filter them by sender address efficiently. Which event declaration and emission pattern is best to achieve this?
event Transfer(address indexed from, address indexed to, uint amount);

function transfer(address to, uint amount) public {
    // transfer logic
    emit Transfer(msg.sender, to, amount);
}
hard
A. Do not use indexed to save gas, filter by reading all events externally
B. Use indexed keyword on sender and receiver to enable filtering in event logs
C. Emit event without parameters to reduce complexity
D. Store all transfers in contract storage instead of events

Solution

  1. Step 1: Understand indexed keyword usage

    Indexed parameters in events allow efficient filtering by those fields in external tools.
  2. Step 2: Evaluate options for tracking transfers

    Use indexed keyword on sender and receiver to enable filtering in event logs uses indexed on sender and receiver, enabling fast filtering by sender address.
  3. Final Answer:

    Use indexed keyword on sender and receiver to enable filtering in event logs -> Option B
  4. Quick Check:

    indexed parameters enable filtering = B [OK]
Hint: Use indexed for filterable event parameters [OK]
Common Mistakes:
  • Avoiding indexed to save gas but losing filtering ability
  • Emitting events without parameters
  • Storing all data on-chain instead of events
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard