0
0
Blockchain / Solidityprogramming~10 mins

Transaction context (tx.origin vs msg.sender) in Blockchain / Solidity - Interactive 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 immediate caller.

Blockchain / Solidity
address caller = [1];
Drag options to blanks, or click blank then click option'
Amsg.sender
Btx.origin
Cthis
Daddress(this)
Attempts:
3 left
💡 Hint
Common Mistakes
Using tx.origin instead of msg.sender when you want the immediate caller.
2fill in blank
medium

Complete the code to get the original external account that started the transaction.

Blockchain / Solidity
address origin = [1];
Drag options to blanks, or click blank then click option'
Amsg.sender
Baddress(this)
Ctx.origin
Dblock.coinbase
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.sender instead of tx.origin to get the original transaction sender.
3fill in blank
hard

Fix the error in the require statement to check the immediate caller is the owner.

Blockchain / Solidity
require([1] == owner, "Not owner");
Drag options to blanks, or click blank then click option'
Amsg.sender
Baddress(this)
Cowner
Dtx.origin
Attempts:
3 left
💡 Hint
Common Mistakes
Using tx.origin in authorization checks, which can be exploited.
4fill in blank
hard

Fill both blanks to create a function that returns the original transaction sender and the immediate caller.

Blockchain / Solidity
function getSenders() public view returns (address origin, address sender) {
    origin = [1];
    sender = [2];
}
Drag options to blanks, or click blank then click option'
Atx.origin
Bmsg.sender
Caddress(this)
Dblock.coinbase
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping tx.origin and msg.sender in the return values.
5fill in blank
hard

Fill all three blanks to create a function that returns the original sender, immediate caller, and contract address.

Blockchain / Solidity
function getContext() public view returns (address origin, address sender, address contractAddr) {
    origin = [1];
    sender = [2];
    contractAddr = [3];
}
Drag options to blanks, or click blank then click option'
Atx.origin
Bmsg.sender
Caddress(this)
Dblock.coinbase
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing contract address with sender addresses.