0
0
Blockchain / Solidityprogramming~10 mins

Emitting events in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Emitting events
Start Transaction
Call Function
Emit Event
Log Event Data
Transaction Ends
Event Available for Listeners
When a function runs, it can emit an event that logs data. This event is stored in the blockchain logs and can be read by apps.
Execution Sample
Blockchain / Solidity
event Sent(address indexed from, address indexed to, uint amount);

function send(address to, uint amount) public {
  emit Sent(msg.sender, to, amount);
}
This code defines an event and emits it inside a function to log a transfer.
Execution Table
StepActionEvaluationResult
1Start transactionN/ATransaction begins
2Call send() with to=0xABC, amount=100Check inputsInputs valid
3Emit Sent eventCreate event log with from=caller, to=0xABC, amount=100Event logged on blockchain
4End transactionN/ATransaction confirmed
5Event availableListeners can read event dataEvent data accessible
💡 Transaction ends after event is emitted and logged
Variable Tracker
VariableStartAfter emitFinal
msg.sendercaller addresscaller addresscaller address
toinput addressinput addressinput address
amountinput uintinput uintinput uint
Event Sentnot emittedemitted with dataemitted with data
Key Moments - 3 Insights
Why do we use 'emit' before the event name?
The 'emit' keyword tells the blockchain to create a log entry for the event. Without 'emit', the event won't be recorded. See execution_table step 3.
Does emitting an event change contract state?
No, emitting an event only logs data. It does not modify variables or contract storage. This is shown in variable_tracker where variables stay the same.
Can external apps read emitted events?
Yes, events are stored in transaction logs and external apps can listen and react to them. See execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 3?
AThe event is emitted and logged on the blockchain
BThe transaction ends without logging
CThe function inputs are checked
DThe event is removed
💡 Hint
Check execution_table row with Step 3 describing event emission
According to variable_tracker, what is the state of 'amount' after emitting the event?
AChanged to zero
BRemains the input value
CUndefined
DIncremented by one
💡 Hint
Look at 'amount' row in variable_tracker after emit column
If the 'emit' keyword is removed, what changes in the execution flow?
AEvent logs twice
BTransaction will fail immediately
CEvent will not be logged, so no event data is available
DFunction inputs become invalid
💡 Hint
Refer to key_moments about the role of 'emit' and execution_table step 3
Concept Snapshot
Syntax: event EventName(params);
Use 'emit EventName(args);' inside functions.
Emitting events logs data on blockchain.
Events do not change contract state.
External apps listen to events for updates.
Full Transcript
Emitting events in blockchain means creating a log entry during a transaction. When a function runs, it can emit an event using the 'emit' keyword followed by the event name and data. This event is stored in the blockchain logs and can be read by external apps or listeners. Emitting events does not change the contract's variables or state; it only records information. The transaction continues and ends after the event is logged. This helps apps track what happened during transactions without changing the blockchain state.