Vyper theorytheory 0/50 · 0%
Functions · easy

7. view, pure and payable

State-mutability decorators and receiving ETH.

`@view` promises the function only reads state, `@pure` promises it touches no state at all, and `@payable` allows the function to receive ETH via `msg.value`. Functions without `@payable` revert if ETH is sent to them.

@external
@view
def rate() -> uint256:
    return self._rate

@external
@payable
def deposit():
    self.balances[msg.sender] += msg.value

As on any EVM chain, a `@view`/`@pure` call made off chain (an `eth_call`) costs the caller no gas because no transaction is mined.

Check your understanding

  1. 1. Which decorator lets a function receive ETH?

  2. 2. What does @pure promise?

  3. 3. What happens if ETH is sent to a non-payable function?