Pyth (Oracle)

Overview

Pyth Networkarrow-up-right is one of the largest first-party Oracle network, delivering real-time data across a vast number of chainsarrow-up-right. The network comprises some of the world’s largest exchanges, market makers, and financial services providersarrow-up-right. These publish proprietary data on-chain for aggregation and distribution to smart contract applications.

Using Pyth Network on Cronos zkEVM

The Pyth introduces an innovative low-latency pull oracle designarrow-up-right, where users can pull price updates onchain when needed, enabling everyone in the onchain environment to access that data point most efficiently. Pyth network updates the prices every 400ms.

Developers Cronos zkEVM have permissionless access to any of Pyth’s price feedsarrow-up-right for equities, ETFs, commodities, foreign exchange pairs, and cryptocurrencies.

Example

Here is a working example of a contract that fetches the latest price of ETH/USD on the Cronos zkEVM. You have to pass Pyth's contract addressarrow-up-right for Cronos zkEVM mainnet/testnet and the desired price feed idarrow-up-right to fetch the latest price.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";

contract MyFirstPythContract {
    IPyth pyth;

    constructor(address _pyth) {
        pyth = IPyth(_pyth);
    }

    function fetchPrice(
        bytes[] calldata updateData,
        bytes32 priceFeed
    ) public payable returns (int64) {
		    // Fetch the priceUpdate from hermes.
        uint updateFee = pyth.getUpdateFee(updateData);
        pyth.updatePriceFeeds{value: updateFee}(updateData);

        // Fetch the latest price
        PythStructs.Price memory price = pyth.getPrice(priceFeed);
        return price.price;
    }
}

Here you can fetch the updateData from Pyth's Hermesarrow-up-right, which listens to Pythnet and Wormhole for price updates; or you can use the pyth-evm-jsarrow-up-right SDK. Check How to Fetch Price Updatesarrow-up-right to pull the latest data.

This packagearrow-up-right provides utilities for consuming prices from the Pyth network oracle using Solidity. Also, it contains the Pyth Interface ABIarrow-up-right that you can use in your libraries to communicate with the Pyth contract.

It is generally recommended to follow the consumer best practicesarrow-up-right when consuming Pyth data.

For more information, check out the official Pyth documentationarrow-up-right. There are details on the various functions available for interacting with the Pyth smart contract in the API Reference sectionarrow-up-right.

Pyth on Cronos zkEVM

Deployment status

  • βœ… Cronos zkEVM Mainnet (Chain-id : 388 )

Mainnet deployment completed - 0x056f829183ec806a78c26c98961678c24fab71afarrow-up-right

  • βœ… Cronos zkEVM Sepolia Testnet (Chain-id : 282 )

Testnet deployment completed - 0xB1DB1498902F08E16E11F1a423ec9CCB9537E1D6arrow-up-right

Additionally, click to access the Pyth price-feed IDsarrow-up-right.

Using Pyth as a PUSH Oracle

Pyth Oracle can be used as a Push oracle by running a scheduler which can update the prices in the backend. It will make sure that the your dapp will be updated with latest prices as per your configuration. Checkout the open source price pusherarrow-up-right app to get started with the scheduler.

Developers and community

The Pyth network provides additional tools to developers, such as TradingView Integrationarrow-up-right, or the Gelato web3 functionsarrow-up-right.

Check out the following links to get started with Pyth.

Last updated