Learn Vyper - 10 Code Examples & CST Typing Practice Test
Vyper is a security-focused, Python-like smart contract programming language for the Ethereum Virtual Machine (EVM). It emphasizes simplicity, readability, and auditability-making it ideal for high-assurance smart contracts.
Learn VYPER with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple Counter Contract
count: public(uint256)
@external
def __init__():
self.count = 0
@external
def increment():
self.count += 1
@external
def reset():
self.count = 0
A minimal counter smart contract using Vyper with increment and reset functions.
Owner-Only Storage
owner: public(address)
message: public(String[100])
@external
def __init__():
self.owner = msg.sender
self.message = ""
@external
def set_message(new_message: String[100]):
assert msg.sender == self.owner
self.message = new_message
A contract where only the owner can update a stored message.
Simple Bank (Deposit + Withdraw)
balances: public(HashMap[address, uint256])
@payable
@external
def deposit():
self.balances[msg.sender] += msg.value
@external
def withdraw(amount: uint256):
assert self.balances[msg.sender] >= amount
self.balances[msg.sender] -= amount
send(msg.sender, amount)
A tiny bank contract allowing users to deposit and withdraw ETH.
ERC20-Like Token (Minimal)
total_supply: public(uint256)
balances: public(HashMap[address, uint256])
@external
def __init__(_s: uint256):
self.total_supply = _s
self.balances[msg.sender] = _s
@external
def transfer(to: address, amount: uint256):
assert self.balances[msg.sender] >= amount
self.balances[msg.sender] -= amount
self.balances[to] += amount
A simplified ERC20-style token for demonstration purposes.
Timestamp Locker
unlock_time: public(uint256)
@payable
@external
def __init__(_unlock: uint256):
self.unlock_time = _unlock
@external
def withdraw():
assert block.timestamp >= self.unlock_time
send(msg.sender, self.balance)
A simple timelock contract where ETH can only be withdrawn after a specific timestamp.
Simple Voting
yes: public(uint256)
no: public(uint256)
@external
def vote(choice: bool):
if choice:
self.yes += 1
else:
self.no += 1
A tiny voting system with yes/no votes.
Whitelist Access
owner: public(address)
whitelist: public(HashMap[address, bool])
@external
def __init__():
self.owner = msg.sender
@external
def add_user(user: address):
assert msg.sender == self.owner
self.whitelist[user] = True
@external
def restricted_action():
assert self.whitelist[msg.sender] == True
A contract that allows only whitelisted addresses to perform an action.
Event Logger
event Log:
creator: address
message: String[100]
@external
def fire(msg: String[100]):
log Log(msg.sender, msg)
A simple example of Vyper events.
Immutable Config
CONFIG: immutable(uint256)
@external
def __init__(v: uint256):
CONFIG = v
@external
def get_config() -> uint256:
return CONFIG
Shows how to use `immutable` variables in Vyper.
Simple Multiplier
factor: public(uint256)
@external
def __init__(_factor: uint256):
self.factor = _factor
@external
def multiply(x: uint256) -> uint256:
return x * self.factor
A utility contract that multiplies a number by a constant stored in the contract.
Frequently Asked Questions about Vyper
What is Vyper?
Vyper is a security-focused, Python-like smart contract programming language for the Ethereum Virtual Machine (EVM). It emphasizes simplicity, readability, and auditability-making it ideal for high-assurance smart contracts.
What are the primary use cases for Vyper?
High-assurance smart contracts. DeFi protocols and vaults. Governance and treasury contracts. Security-audited financial logic. Minimalistic EVM dApps
What are the strengths of Vyper?
High security and predictability. Easy to read and audit. Minimal attack surface. Formally verifiable. Ideal for critical DeFi contracts
What are the limitations of Vyper?
No inheritance. No modifiers. Limited built-in tooling vs Solidity. Smaller ecosystem. Not ideal for highly complex contracts
How can I practice Vyper typing speed?
CodeSpeedTest offers 10+ real Vyper code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.