Why Update Prices
Understand why Pyth pull-oracle integrations must refresh on-chain prices
Pyth uses a pull oracle model. Unlike traditional push oracles that automatically update prices on-chain at regular intervals, Pyth requires users to explicitly update the on-chain price before reading it.
This design offers several advantages:
- Lower costs: You only pay for price updates when you need them
- Lower latency: You can fetch the latest price update directly from Pyth's low-latency oracle network and submit it on-chain immediately
- Flexibility: Different applications can update prices at different frequencies based on their needs
In the pull integration pattern, your contract must:
- Accept
priceUpdatedata from the caller (fetched from Hermes) - Call
updatePriceFeeds()to submit this data on-chain before reading prices - Pay a small fee for each update (calculated via
getUpdateFee())
If you don't update the price or if the on-chain price becomes too stale, calls to getPriceNoOlderThan() will revert with a StalePrice error. See how to fetch price updates for more details on obtaining price updates.