1/5
## Calling External Contracts in Vyper We are going to make sure that we use the proper keyword when we call external contracts. In Solidity, it's pretty straightforward. We just call an external contract. However, Vyper, we need to use a specific keyword. If we are calling a view function or don't want to change any state, we use `staticcall`. Otherwise, we use `extcall`, which stands for external call. We will use the following code block to demonstrate how to call an external contract using `staticcall` in Vyper. ```python price_feed: AggregatorV3Interface = AggregatorV3Interface(0x6944AA1769357215DE4FAC081bf1f309aDC325306) return staticcall price_feed.latestAnswer() ``` So, in this code block, we're first defining a variable called `price_feed` and setting it to an object of type `AggregatorV3Interface`. Next, we are saying that we want to return the value returned by the `latestAnswer` function, which is a view function in this case. We use `staticcall` since we are calling a view function. This means that we are not going to change any state in our contract.
A practical Vyper tutorial on calling external contracts using staticcall and extcall. This lesson delves into the distinction between staticcall and extcall for accessing functions in external contracts, highlighting the importance of security considerations and the use of view functions.
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