For the complete documentation index, see llms.txt. This page is also available as Markdown.

Pyth

Overview

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

Pyth offers two oracle products: Pyth Core for standard price feeds, and Pyth Pro for more advanced data needs. Only Pyth Pro is supported in Cronos network.

Using Pyth as a PULL Oracle

Pyth Pro follow a pull oracle model: rather than an oracle operator periodically updating prices on-chain, anyone can fetch the latest signed price data from an off-chain service and submit it on-chain as part of their transaction. The smart contract then verifies and reads the price within that same transaction.

Pyth Pro Quick Guide

Pyth Pro (formerly Pyth Lazer) is a high-performance, enterprise-grade, low-latency service that delivers customizable real-time price data from first-party publishers, with configurable update schedules.

Example

Backend: Fetch Price Updates

The following example shows how to subscribe to Pyth Pro price updates using the @pythnetwork/pyth-lazer-sdk. The returned payload includes a verified binary that can be submitted on-chain.

  • Config API Key

    Request a Pyth Pro API key by following the steps on the Acquire an API key page. Once obtained, set it as an environment variable:

    export PYTH_PRO_API_KEY=your_api_key_here
  • Install the SDK

    npm install --save @pythnetwork/pyth-lazer-sdk
  • Subscribe to price updates

    import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
    
    // Create a client connected to all three endpoints for redundancy, a single endpoint may go down briefly during deployments.
    const client = await PythLazerClient.create({
      urls: [
        "wss://pyth-lazer-0.dourolabs.app/v1/stream",
        "wss://pyth-lazer-1.dourolabs.app/v1/stream",
        "wss://pyth-lazer-2.dourolabs.app/v1/stream",
      ],
      token: process.env.PYTH_PRO_API_KEY,
    });
    
    // The message listener is called every time a new message is received.
    client.addMessageListener((message) => {
      // Add your logic to consume messages here
      console.log("got message:", message);
    });
    
    // Subscribe to price feeds (price feed IDs from Pyth Pro price feed list)
    client.subscribe({
      type: "subscribe",
      subscriptionId: 1,
      priceFeedIds: [1, 2],
      properties: ["price", "feedUpdateTimestamp"],
      formats: ["evm"],
      channel: "fixed_rate@200ms",
      ignoreInvalidFeeds: true,
    });

Refer to the Pyth Pro documentation for the full list of subscription parameters, channels. See the Payload Reference for details on the payload structure, and the Price Feed IDs page for supported feeds.

Smart Contract: Verify and Parse Price Data

Here is a working example of a contract that verifies and parses a Pyth Pro price update. You have to pass Pyth's contract address for Cronos EVM mainnet/testnet.

This package provides a working example contract that parses and consumes price updates from Pyth Pro on EVM, along with the Solidity SDK used to verify and parse payloads.

Pyth on Cronos EVM

Pyth Pro Contract Addresses

Using Pyth as a PUSH Oracle

Pyth Core 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

Check out the following links to get started with Pyth.

Last updated

Was this helpful?