1/5
We are going to create a simple smart contract to teach you how to use Chainlink price feeds. We are going to use Remix to create this smart contract, with the following code. We will explain this code in detail later. ```python # @license: MIT # @author: You! minimum_usd: uint256 @deploy def __init__(): self.minimum_usd = 5 @external @payable def fund(): """Allows users to send $ to this contract. Have a minimum $ amount send """ # How do we convert the ETH amount to dollars amount? assert msg.value >= self.minimum_usd, "You must spend more ETH!" @external def withdraw(): pass ``` We want users to send us the minimum USD value. In this example, we have set this value to 5. So how do we convert this ETH amount to dollars? First, let's create a new function for this conversion. ```python @internal def get_eth_to_usd_rate(): # Address: 0x9aA77716935D5E4AC08b1f17f309aC232d236858 # ABI pass ``` We will need to obtain the price of ETH in dollars. Chainlink provides price feeds, which we can use for this conversion. We will need to get the Chainlink price feed address for the network we are working with. We can find this information in the Chainlink documentation. We are going to be working with the Sepolia testnet, and we can find the address for the ETH / USD price feed there. We have the address for the Chainlink price feed. Now, we need the ABI or the Application Binary Interface. This interface defines the functions of the Chainlink price feed contract. The ABI is also available in the Chainlink documentation. ```python @internal def get_eth_to_usd_rate(): # Address: 0x9aA77716935D5E4AC08b1f17f309aC232d236858 # ABI eth_usd_price_feed = Contract("0x9aA77716935D5E4AC08b1f17f309aC232d236858", get_eth_to_usd_rate_abi) # Now, we can call the latestRoundData function # of the price feed and store it as a tuple. # latestRoundData is a function that returns the latest round data for the price feed. # It returns a tuple of four values: # - current round # - latest answer # - latest timestamp # - latest updated timestamp # The second element of this tuple, # latest answer, is the latest price # of ETH in dollars. ( # current round , # latest answer latest_answer # latest timestamp , # latest updated timestamp , ) = eth_usd_price_feed.latestRoundData() return latest_answer ```
A comprehensive guide to using Chainlink Price Feeds in Vyper smart contracts. The lesson covers how to read price data from a Chainlink Price Feed contract, how to set up the development environment, and how to use the Chainlink documentation for further assistance.
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