Solidity theorytheory 0/50 · 0%
Foundations · easy

15. msg, tx and block

Context variables you will use in every contract.

`msg.sender` is the immediate caller, `msg.value` the ETH sent, `msg.data` the raw calldata. `block.timestamp` and `block.number` describe the block. `tx.origin` is the original externally owned account.

Never use `tx.origin` for authorisation: an intermediate malicious contract can call yours while `tx.origin` is still the victim.

require(msg.sender == owner, "not owner");
uint256 t = block.timestamp;

`block.timestamp` can be nudged slightly by proposers, so do not use it for fine-grained randomness or sub-second logic.

Check your understanding

  1. 1. Why is `tx.origin` unsafe for auth?

  2. 2. What is `msg.value`?

  3. 3. How trustworthy is `block.timestamp`?