Pyth is live
on Aptos

With the recent launch of Pythnet - a dedicated app-chain for Pyth price aggregation - and the integration with the Wormhole Protocol, your dApp can now permissionlessly request and consume any of the 200+ Pyth price feeds directly on Aptos.

What is Pyth?

The Pyth network is a first-party financial oracle network designed to publish continuous real-world data on-chain in a tamper-resistant, decentralized, and self-sustainable environment.

The network is designed to incentivize market participants — exchanges, market makers, and financial services providers — to share directly on-chain the price data collected as part of their existing operations. The network then aggregates this first-party price data and makes it available for free to either on- or off-chain applications.

In less than a year, the network secured more than $2.0B in total value, supported up to $3.8B in monthly trading volume ($30B+ in total), and exceeded 500K client downloads.

Pyth currently supports 200+ price feeds including crypto, equities (including the full US 30), FX, metals and more — and updates twice per second without any access restriction. It will also soon support Aptos ecosystem tokens.

More details can be found here.

How does Pyth Work
on Aptos ?

Pyth prices are published on Pythnet and relayed to Aptos using the Wormhole Network as a cross-chain message passing protocol. Wormhole observes when Pyth prices on Pythnet have changed and publishes an off-chain signed message attesting to this fact.

This signed price update message can then be submitted to the Pyth contract. The contract verifies the Wormhole message and updates the on-chain Pyth price to the new price.

Pyth does not automatically submit the prices to the Aptos networks; protocols and users are responsible for updating the on-chain Pyth price before using it.

To learn more, please visit our docs.

How to integrate Pyth
feeds on Aptos

Pyth stores prices off-chain to minimize gas fees, which allows us to offer a wider selection of products and faster update times. To use Pyth prices on-chain, they must be fetched from an off-chain price service.

The AptosPriceServiceConnection class can be used to interact with these services, providing a way to fetch these prices directly in your code. The following example wraps an existing RPC provider and shows how to obtain Pyth prices and submit them to the network:

1const connection = new AptosPriceServiceConnection(
2const connection = new AptosPriceServiceConnection(
3  ""
4); // See Price Service endpoints section below for other endpoints
6const priceIds = [
7  // You can find the ids of prices at
8  "0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b", // BTC/USD price id in testnet
9  "0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6", // ETH/USD price id in testnet
12// 'getPythLatestPriceFeeds' returns a 'PriceFeed' for each price id. It contains all information about a price and has
13// utility functions to get the current and exponentially-weighted moving average price, and other functionality.
14const priceFeeds = connection.getPythLatestPriceFeeds(priceIds);
15console.log(priceFeeds[0].getCurrentPrice()); // Price { conf: '1234', expo: -8, price: '12345678' }
16console.log(priceFeeds[1].getEmaPrice()); // Exponentially-weighted moving average price
18// In order to use Pyth prices in your protocol you need to submit the price update data to Pyth contract in your target
19// chain. 'getPriceUpdateData' creates the update data which can be submitted to your contract. Then your contract should
20// call the Pyth Contract with this data.
21const priceUpdateData = await connection.getPriceUpdateData(priceIds);
23// Create a transaction and submit to your contract using the price update data
24const client = new AptosClient(endpoint);
25let result = await client.generateSignSubmitWaitForTransaction(
26  sender,
27  new TxnBuilderTypes.TransactionPayloadEntryFunction(
28    TxnBuilderTypes.EntryFunction.natural(
29      "0x..::your_module",
30      "do_something",
31      [],
32      [priceUpdateData]
33    )
34  )

Start integrating

Read the Docs