Vyper theorytheory 0/50 · 0%
Foundations · easy

2. Version pragma and file layout

Pinning the compiler version and structuring a Vyper module.

Every Vyper file should declare the compiler version it was written for using a comment pragma. This isn't optional style — the compiler refuses to build if the installed version falls outside the stated range.

A typical file layout is: version pragma, imports/interfaces, state variables, events, constructor, then external and internal functions grouped by purpose.

# @version ^0.3.10

from vyper.interfaces import ERC20

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

event Deposited:
    amount: uint256

Unlike Solidity's `pragma solidity`, Vyper's version comment must start with `# @version` and is checked strictly against the installed compiler.

Check your understanding

  1. 1. How is the compiler version declared in Vyper?

  2. 2. What happens if the installed compiler doesn't match the pragma?

  3. 3. Where do interface imports typically go in a Vyper file?