Vyper theorytheory 0/50 · 0%
Foundations · easy

19. Global variables: msg, block, tx

Reading transaction and block context.

Vyper exposes the same environment globals as Solidity, spelled slightly differently in some cases: `msg.sender`, `msg.value`, `msg.gas`, `block.timestamp`, `block.number`, `block.prevrandao`, and `tx.origin`.

@external
@payable
def deposit():
    assert msg.value > 0, "send something"
    self.deposits[msg.sender] += msg.value
    self.last_block[msg.sender] = block.number

As on any EVM chain, prefer `msg.sender` over `tx.origin` for authorization checks — `tx.origin` is the original externally-owned account and is vulnerable to phishing via an intermediate contract.

Check your understanding

  1. 1. Which global holds the amount of ETH sent with a call?

  2. 2. Why avoid tx.origin for authorization?

  3. 3. Which global gives the current block number?