0
0
Blockchain / Solidityprogramming~10 mins

msg.value and msg.sender in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the address of the caller.

Blockchain / Solidity
address caller = [1];
Drag options to blanks, or click blank then click option'
Amsg.value
Baddress(this)
Ctx.origin
Dmsg.sender
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.value instead of msg.sender
Using tx.origin which is less secure
Using address(this) which is the contract's address
2fill in blank
medium

Complete the code to get the amount of Ether sent with the call.

Blockchain / Solidity
uint amount = [1];
Drag options to blanks, or click blank then click option'
Atx.gasprice
Bmsg.value
Cmsg.sender
Dmsg.gas
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.sender instead of msg.value
Using tx.gasprice which is gas price, not value
Using msg.gas which is deprecated
3fill in blank
hard

Fix the error in the function to correctly check if Ether was sent.

Blockchain / Solidity
function deposit() public payable {
    require([1] > 0, "Send some Ether");
}
Drag options to blanks, or click blank then click option'
Amsg.value
Btx.origin
Caddress(this).balance
Dmsg.sender
Attempts:
3 left
💡 Hint
Common Mistakes
Checking msg.sender instead of msg.value
Using address(this).balance which is total contract balance
4fill in blank
hard

Fill both blanks to create a function that returns the sender and the amount sent.

Blockchain / Solidity
function getInfo() public view returns (address, uint) {
    return ([1], [2]);
}
Drag options to blanks, or click blank then click option'
Amsg.sender
Bmsg.value
Ctx.origin
Daddress(this)
Attempts:
3 left
💡 Hint
Common Mistakes
Returning tx.origin instead of msg.sender
Returning address(this) instead of msg.sender
Returning msg.sender and tx.origin mixed
5fill in blank
hard

Fill all three blanks to create a payable function that stores sender and amount in state variables.

Blockchain / Solidity
address public lastSender;
uint public lastAmount;

function recordPayment() public payable {
    lastSender = [1];
    lastAmount = [2];
    emit PaymentReceived([3]);
}

event PaymentReceived(address sender);
Drag options to blanks, or click blank then click option'
Amsg.sender
Bmsg.value
DlastSender
Attempts:
3 left
💡 Hint
Common Mistakes
Using lastSender instead of msg.sender in the event
Mixing up msg.sender and msg.value assignments