Understanding msg.value and msg.sender in Solidity
📖 Scenario: You are creating a simple smart contract for a crowdfunding campaign on the Ethereum blockchain. People can send money to support the project, and the contract keeps track of who sent money and how much.
🎯 Goal: Build a smart contract that records the sender's address and the amount of Ether sent using msg.sender and msg.value. Then display the total amount collected and the last sender's address.
📋 What You'll Learn
Create a public variable
lastSender to store the address of the last person who sent EtherCreate a public variable
totalCollected to store the total amount of Ether collectedWrite a
receive function to accept Ether and update lastSender and totalCollectedWrite a function
getSummary that returns lastSender and totalCollected💡 Why This Matters
🌍 Real World
Smart contracts on Ethereum use <code>msg.sender</code> and <code>msg.value</code> to handle payments and identify users.
💼 Career
Understanding these variables is essential for blockchain developers building decentralized applications that handle money.
Progress0 / 4 steps