1/5
The first question that will come up is how do we send ETH to this contract? The answer to this is that in every transaction you send, there's a value field that allows you to send a certain amount of ETH. You can even see this in Metamask, where you can send a specific amount of ETH to an address. This populates the value field in the transactions. Not all functions can read from this value field. To tell a function that it can read from the value field, we use the `@payable` keyword. This tells Vyper that the function can work with the `msg.value` variable. Similar to wallets, smart contracts can hold funds. To ensure someone calling the `fund` function sends at least one ETH, we can use the `assert` function and say: ```python assert msg.value == 1000000000000000000 ``` We'll understand what `wei` is later on. We also have a variable called `msg.sender`, which is the sender of the current message. We will be using this variable in our code.
A practical guide to sending ETH to a Vyper smart contract - The lesson explains how to use the @payable decorator in Vyper to enable a smart contract to receive ETH and use the msg.value environment variable to access the amount of ETH sent in a transaction.
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)
Last updated on May 15, 2025
Vyper Developer
Introduction to Python and VyperDuration: 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)
Last updated on May 15, 2025