Pyth

Overview

Pyth Network is one of the largest first-party Oracle network, delivering real-time data across a vast number of chains. The network comprises some of the worldโ€™slargest exchanges, market makers, and financial services providers. These publish proprietary data on-chain for aggregation and distribution to smart contract applications.

Using Pyth Network on Cronos EVM

The Pyth introduces an innovative low-latency pull oracle design, 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 on Cronos EVM have permissionless access to any of Pythโ€™s price feeds 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 network. You have to pass Pyth's contract address for Cronos EVM mainnet/testnet and the desired price feed id 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 Hermes, which listens to Pythnet and Wormhole for price updates; or you can use the pyth-evm-js SDK. Check How to Fetch Price Updates to pull the latest data.

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

It is generally recommended to follow the consumer best practices when consuming Pyth data.

For more information, check out the official Pyth documentation. There are details on the various functions available for interacting with the Pyth smart contract in the API Reference section.

Pyth on Cronos EVM

The Pyth Network smart contract is available at the following address:

Cronos EVM

Additionally, click to access the Pyth price-feed IDs.

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. Checkout the open source price pusher app to get started with the scheduler.

Developers and community

The Pyth network provides additional tools to developers, such as

Check out the following links to get started with Pyth.

Last updated