1/5
In this lesson we will continue working with our _buy-me-a-coffee_ smart contract. We will introduce a few more key fundamentals to help us understand the basics of smart contract development in Vyper. We'll then move on to more complex aspects later in the course. Here is the code we are working with so far: ```python #pragma version 0.4.1 @license MIT @title Buy Me A Coffee! @author You! @notice This contract is for creating a sample funding contract # We'll learn a new way to do interfaces later... interface AggregatorV3Interface: def decimals() -> uint8: view def description() -> String[1000]: view def version() -> uint256: view def latestAnswer() -> int256: view # Constants & Immutables MINIMUM_USD: public(constant(uint256)) = as_wei(value=5, "ether") PRICE_FEED: public(immutable(AggregatorV3Interface)) = 0x6944AA1769357215DE4FAC081f113094dC325306 sep0lia # ABI Address OWNER: public(immutable(address)) PRECISION: constant(uint256) = 1 * (10 ** 18) # Storage funders: public(DynArray[address, 1000]) funder_to_amount_funded: public(HashMap[address, uint256]) # With constants: 262, 853 @deploy def __init__(price_feed: address): PRICE_FEED = AggregatorV3Interface(price_feed) OWNER = msg.sender @external @payable def fund(): """Allows users to send $ to this contract Have a minimum $ amount to send """ usd_value_of_eth: uint256 = self.get_eth_to_usd_rate(msg.value) assert usd_value_of_eth >= MINIMUM_USD, "You must spend more ETH!!" self.funders.append(msg.sender) self.funder_to_amount_funded[msg.sender] += msg.value ``` In this code, we have: - A _decimals_ function which returns a uint8 value. - A _description_ function which returns a String value. - A _version_ function which returns a uint256 value. - A _latestAnswer_ function which returns an int256 value. - We have declared the constants _MINIMUM_USD_, _PRICE_FEED_, _OWNER_, and _PRECISION_. - We have declared the storage variables _funders_ and _funder_to_amount_funded_. - We have declared the initializer function **_init_**. - We have declared the _fund_ function which is payable and allows users to send ETH to the contract. The topics we've covered so far are: - Interfaces - Constants - Immutables - Storage - Initializers - Payable Decorators - Function Documentation We have also seen how to use `msg.sender`, `msg.value`, and `self` in our code. We will cover more advanced topics later in the course.
A comprehensive overview of Vyper fundamentals - This lesson covers concepts such as interfaces, constants and immutables, arrays, mappings, constructors, decorators, and sending money from within a contract.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Last updated on April 21, 2025
Duration: 2h 08min
Duration: 2h 32min
Duration: 24min
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Last updated on April 21, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar