1/5
## Making a function call another function In this lesson, we'll learn about making a function call another function in Vyper. We'll use an example of a function that takes an amount of ETH in Wei and converts it to USD. First, we create a function to do the calculation. ```python def get_eth_to_usd_rate(eth_amount: uint256) -> uint256: """ Chris sent us 0.01 ETH for us to buy a coffee: Is that more or less than $5? """ eth_price: uint256 = staticcall(self.price_feed, latestAnswer()) * (10 ** 10) price_in_usd: uint256 = (convert(uint256, price) * eth_amount) // (1 * 10 ** 18) eth_amount_in_usd_uint256: uint256 = price_in_usd * eth_amount // (1 * 10 ** 18) return eth_amount_in_usd_uint256 # 18 0's, 18 decimal places ``` We can create an external function that runs our internal function. ```python @external @view def get_eth_to_usd_rate(eth_amount: uint256) -> uint256: return self._get_eth_to_usd_rate(eth_amount) ``` We'll say ETH amount uint256 returns a uint256. All we got to do is say return self.\_get_eth_to_usd_rate(eth_amount). This creates an external function `get_eth_to_usd_rate` that calls the internal function `_get_eth_to_usd_rate` passing the `eth_amount` as an argument. This is a useful technique when you need to expose an internal function. It allows you to keep internal functions private while still providing an external interface to access their functionality.
A practical Vyper tutorial on making a function call another function. The lesson covers how to create an external function that runs an internal function and passes in arguments. It also discusses the importance of using underscores in function names.
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