Vyper theorytheory 0/50 · 0%
Foundations · easy

18. Constructor: __init__

Deploy-time setup with __init__.

`__init__` is Vyper's constructor. It runs exactly once at deployment and is decorated with `@deploy` in modern versions (previously it needed no decorator). It's where you set the owner, wire up immutables, and perform any one-time setup.

owner: public(address)
token: immutable(address)

@deploy
def __init__(token_: address):
    self.owner = msg.sender
    token = token_

Like in Solidity, the constructor's bytecode is stripped from what actually gets stored on chain — only the resulting state and runtime code remain.

Check your understanding

  1. 1. What is Vyper's constructor function called?

  2. 2. How many times does __init__ run?

  3. 3. Which decorator marks the constructor in modern Vyper?