Vyper Smart Contract Compiler
Vyper is a Pythonic programming language for the Ethereum Virtual Machine (EVM), designed with security, auditability, and simplicity in mind. It provides a more constrained set of features compared to other EVM languages, aiming to reduce complexity and potential vulnerabilities. The current version is 0.4.3, with minor releases and release candidates occurring frequently, typically leading to stable minor versions every few months.
Common errors
-
ModuleNotFoundError: No module named 'vyper'
cause The Vyper library has not been installed in the current Python environment.fixRun `pip install vyper` to install the library. -
SyntaxException: line X:X 'some_invalid_keyword' is not allowed
cause There is a syntax error or an attempt to use a non-existent keyword or feature in your Vyper contract code.fixReview the Vyper contract code against the official Vyper documentation for the specific version you are using. Vyper has a minimalist design, so many Solidity features are not present. -
ValueError: Vyper does not support python version 3.9.x (or similar for other unsupported versions)
cause You are attempting to run Vyper with an unsupported Python version. Vyper typically requires Python 3.10+ but less than 4.fixSwitch your Python environment to a compatible version (e.g., 3.10, 3.11, 3.12). You can use `pyenv install 3.12.0 && pyenv local 3.12.0` or create a new virtual environment with the correct Python version. -
KeyError: 'bytecode' (or 'abi') when accessing compiled_artifacts
cause The specified `output_formats` in `compile_code` did not include the key you are trying to access, or compilation failed silently without producing all artifacts.fixEnsure that the `output_formats` list explicitly includes all the keys you intend to access (e.g., `['bytecode', 'abi', 'ast_dict']`). Check for compilation errors if outputs are still missing.
Warnings
- breaking Vyper adheres to a `0.x.x` versioning scheme, meaning breaking changes can occur in minor releases. Always review release notes when upgrading between `0.X.x` versions (e.g., from 0.3.x to 0.4.x).
- breaking The default EVM version targeted by the compiler can change in minor releases (e.g., to 'prague' in v0.4.3). This might affect bytecode generation and compatibility with specific chain deployments if not explicitly handled.
- gotcha Vyper requires Python 3.10 or higher, but strictly less than Python 4.0. Running with an unsupported Python version will lead to installation or runtime errors.
- breaking Recent releases (e.g., v0.4.1) have included security-related fixes for low-to-moderate severity vulnerabilities. Older versions may contain known security flaws.
- gotcha Experimental compiler features, such as the `--venom` or `--experimental-codegen` flags (aliases), are subject to rapid change, may contain bugs, or produce unoptimized/unexpected bytecode. They are not recommended for production deployments.
Install
-
pip install vyper
Imports
- compile_code
import vyper.compiler
from vyper import compile_code
Quickstart
from vyper import compile_code
contract_code = '''
# @version ^0.4.0
# A simple Vyper contract
@external
def hello() -> String[100]:
return "Hello, Vyper!"
'''
# Compile the contract to get bytecode, ABI, and other artifacts
compiled_artifacts = compile_code(
contract_code,
output_formats=['bytecode', 'abi'],
evm_version='shanghai' # Specify EVM version for compatibility
)
print("Bytecode:", compiled_artifacts['bytecode'])
print("ABI:", compiled_artifacts['abi'])