Emitting Events in a Smart Contract
📖 Scenario: You are creating a simple smart contract on the blockchain that tracks when a user sends a greeting message. You want to record each greeting by emitting an event so that external apps can listen and react to these greetings.
🎯 Goal: Build a Solidity smart contract that emits an event every time a greeting is sent. This event should include the sender's address and the greeting message.
📋 What You'll Learn
Create an event called
Greeted with parameters address sender and string message.Create a public function called
sendGreeting that takes a string memory message as input.Emit the
Greeted event inside the sendGreeting function with the sender's address and the message.Test the contract by calling
sendGreeting and ensure the event is emitted.💡 Why This Matters
🌍 Real World
Events are used in blockchain apps to notify wallets, user interfaces, and other contracts about important actions like transfers, votes, or messages.
💼 Career
Blockchain developers must know how to emit and listen to events to build responsive decentralized applications (dApps) and smart contracts.
Progress0 / 4 steps