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)
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