0
0
Blockchain / Solidityprogramming~5 mins

Transaction context (tx.origin vs msg.sender) in Blockchain / Solidity - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What does msg.sender represent in a blockchain transaction?

msg.sender is the immediate address that called the current function. It can be a user or another contract.

Click to reveal answer
beginner
What is tx.origin in a blockchain transaction?

tx.origin is the original external account (user) that started the transaction, regardless of how many contracts were called in between.

Click to reveal answer
intermediate
Why is using tx.origin for authorization considered risky?

Because tx.origin points to the original user, a malicious contract can trick your contract by forwarding calls, making your contract trust the wrong sender.

Click to reveal answer
intermediate
In a call chain: User → Contract A → Contract B, what does msg.sender equal inside Contract B?

Inside Contract B, msg.sender is Contract A's address, the immediate caller.

Click to reveal answer
beginner
Which is safer to use for access control: msg.sender or tx.origin?

msg.sender is safer because it checks the immediate caller, reducing risks of phishing attacks through intermediate contracts.

Click to reveal answer
What does tx.origin represent in a transaction?
AThe original external account that started the transaction
BThe immediate caller of the current function
CThe contract address executing the code
DThe miner who included the transaction
Inside a contract, msg.sender is:
AThe original user who started the transaction
BThe blockchain network
CThe contract owner
DThe immediate caller of the function
Why should you avoid using tx.origin for authorization checks?
AIt is slower to access
BIt can be tricked by malicious contracts forwarding calls
CIt can be spoofed by miners
DIt does not exist in smart contracts
In a call chain User → Contract A → Contract B, what is msg.sender inside Contract B?
AUser address
BTransaction origin address
CContract A address
DContract B address
Which is the best practice for checking who called your contract for security?
AUse <code>msg.sender</code>
BUse <code>tx.origin</code>
CUse the miner's address
DUse a random address
Explain the difference between tx.origin and msg.sender in a blockchain transaction.
Think about who started the transaction versus who called the current function.
You got /4 concepts.
    Why is it risky to use tx.origin for authorization in smart contracts?
    Consider how calls can be forwarded through multiple contracts.
    You got /4 concepts.