0
0
Blockchain / Solidityprogramming~20 mins

Indexed parameters in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Indexed Parameters in Blockchain Events
📖 Scenario: You are building a simple smart contract on the Ethereum blockchain. This contract will emit events when users send messages. You want to learn how to use indexed parameters in events to make it easier to search for specific data in the blockchain logs.
🎯 Goal: Create a Solidity contract that defines an event with indexed parameters, emits this event when a message is sent, and then prints the event data (simulated in code comments) to understand how indexed parameters work.
📋 What You'll Learn
Define an event called MessageSent with two indexed parameters: address sender and string message
Create a function called sendMessage that emits the MessageSent event
Use exactly the variable names sender and message in the event
Emit the event with msg.sender as sender and a string parameter as message
💡 Why This Matters
🌍 Real World
Blockchain developers use indexed parameters in events to quickly find specific transactions or actions in large blockchain data.
💼 Career
Understanding indexed parameters is essential for blockchain developers working on smart contracts and decentralized applications that require efficient event filtering.
Progress0 / 4 steps
1
Create the basic contract and event
Write a Solidity contract named MessageContract. Inside it, define an event called MessageSent with two indexed parameters: address indexed sender and string indexed message.
Blockchain / Solidity
Need a hint?

Use the event keyword and add indexed before the parameters you want to index.

2
Add the sendMessage function
Inside the MessageContract, add a public function called sendMessage that takes a string memory message parameter. This function should emit the MessageSent event with msg.sender as sender and the message parameter.
Blockchain / Solidity
Need a hint?

Use the emit keyword to send the event with the correct parameters.

3
Explain the role of indexed parameters
Add a comment inside the contract explaining that indexed parameters allow filtering events by those parameters when searching blockchain logs.
Blockchain / Solidity
Need a hint?

Write a simple comment starting with // inside the contract.

4
Simulate event output
Write a comment below the contract showing an example output of the MessageSent event when sendMessage is called by address 0x123... with message "Hello". Show the indexed parameters clearly.
Blockchain / Solidity
Need a hint?

Write the example output as a comment exactly as shown.