Skip to main content

Pyth

The Pyth network a first-party oracle network, securely and transparently delivering real-time market data to multiple 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 price feeds

The Pyth network introduces an innovative low-latency pull oracle design, where users can pull price updates on-chain when needed, enabling everyone in the blockchain environment to access that data point. Pyth network updates the prices every 400ms, making Pyth the fastest on-chain oracle.

Here is a working example of a contract that fetches the latest price of ARB/USD on the Arbitrum network.

You have to pass Pyth's contract address for Arbitrum mainnet/testnet and the desired price feed ID to fetch the latest price.

Install the Pyth SDK Solidity package in your project:

npm install @pythnetwork/pyth-sdk-solidity

And then, in a few lines of code you can fetch the latest price on the Arbitrum network.

// 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;
// Pass the address of Pyth's contract for Arbitrum mainnet(0xff1a0f4744e8582DF1aE09D5611b887B6a12925C)
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 feed, 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.

Pyth Entropy

Pyth Entropy allows developers to quickly and easily generate secure random numbers on the blockchain.

Check how to generate random numbers in EVM contracts for a detailed walkthrough.

Supported networks for Arbitrum(Pyth Entropy):

Additional resources

Check out the following links to get started with Pyth: