Vyper theorytheory 0/50 · 0%
Functions · easy

6. Functions and decorators

@external, @internal and how Vyper replaces Solidity's function modifiers.

Every function in Vyper needs an explicit decorator: `@external` for functions callable from outside the contract, `@internal` for helpers only callable via `self.`. There is no default visibility, unlike Solidity.

@external
def stake(amount: uint256):
    self._credit(msg.sender, amount)

@internal
def _credit(user: address, amount: uint256):
    self.balances[user] += amount

A common convention mirrors Solidity: prefix internal helpers with an underscore so the intent is obvious at a glance.

Check your understanding

  1. 1. Which decorator makes a function callable only inside the contract (via self.)?

  2. 2. Does Vyper have a default function visibility?

  3. 3. How do you call an internal helper from another function?