API Reference

updatePriceFeeds

Update the on-chain price feeds using the provided updateData.

Description

This method updates the on-chain price feeds using the provided updateData, which contains serialized and signed price update data from Pyth Network. You can retrieve the latest price updateData for a given set of price feeds from the Hermes API.

This method updates the on-chain price if the provided update is more recent than the current on-chain price. Otherwise, the provided update will be ignored. The method call will succeed even if the update is ignored.

This function requires the caller to pay a fee to perform the update. The required fee for a given set of updates can be computed by passing them to getUpdateFee.

This method returns the transaction hash of the update transaction.

Error Response

The above method can return the following error response:

  • InvalidUpdateData: The provided update data is invalid or incorrectly signed.
  • InsufficientFee: The fee provided is less than the required fee. Try calling getUpdateFee to get the required fee.

Arguments

  • The price update data for the contract to verify. Fetch this data from Hermes API.

  • The update fee in wei. This fee is sent as the value of the transaction.

Examples

import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
//
address contractAddress =
IPyth pyth = IPyth(contractAddress);
bytes[] memory updateData = new bytes[](1);
updateData[0] = /* <updateData> */;
uint fee = /* <fee> */;
pyth.updatePriceFeeds{value: fee}(updateData);