0/5
## Better way to send ETH We've learned how to send ETH to another account using the `send` function. However, there's a better way to do it that's considered more secure. The `send` function is a lower-level function that can be unreliable. There are potential issues with how much gas the EVM uses for different opcodes (for example, logging), and this could cause transactions to fail. Instead, we're going to use the `raw_call` function. This is a built-in function in Vyper that allows us to call any function in the world, even if the target contract doesn't have that function. Let's look at how to use `raw_call` to send ETH. We'll use the `withdraw` function as an example. ```vyper @external def withdraw(): """Take the money out of the contract, that people sent via the fund function. How do we make sure we can pull the money out? ..... """ assert msg.sender == OWNER, "Not the contract owner!" #send(OWNER, self.balance) raw_call(OWNER, b"", value=self.balance) revert_on_failure=True #resetting for funder, address in self.funders: self.funder_to_amount_funded[funder] = 0 self.funders = [] ``` **Explanation:** - `raw_call(OWNER, b"", value=self.balance)` calls the raw call function. - The first argument `OWNER` is the address we're sending ETH to. - The second argument `b""` is an empty byte string that represents the data we're sending. - The third argument `value=self.balance` is the amount of ETH we're sending, which is the contract's current balance. - `revert_on_failure=True` tells Vyper to revert the transaction if `raw_call` fails. We can learn more about `raw_call` and its advanced features in later lessons. For now, understand that `raw_call` is considered a safer way to send ETH than using the `send` function.
A comprehensive guide to sending Ether in Vyper. This lesson covers the use of the send keyword and its potential security risks, as well as the more advanced, secure method of sending ETH using the raw_call built-in function.
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