You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pyth price feeds on Sui are uniquely represented in the global store as `PriceInfoObjects`. These objects have the `key` ability and serve as wrappers around the `PriceInfo` object, which in turn contains the price info: namely the `PriceFeed`, the arrival time of the latest price update, and the attestation time of the latest update.
3
+
# How to Use Real-Time Data in Sui Contracts
4
4
5
-
`PriceInfoObject`s are central to Pyth on Sui, since they are in unique correspondence with each Pyth price feed and must be passed in to functions that update price feeds or which query info about price feeds, e.g.
5
+
This guide explains how to use real-time Pyth data in Sui applications.
6
6
7
-
-`update_single_price_feed`
8
-
-`update_single_price_feeds_if_fresh`
9
-
-`get_price`
7
+
## Install Pyth SDK
10
8
11
-
## How to Update and Consume Price Feeds
12
-
13
-
We provide a javascript sdk to use for constructing transaction blocks which updates price feeds.
14
-
15
-
### Installation
16
-
17
-
If you are using npm run:
9
+
Use the following dependency in your `Move.toml` file to use the latest Pyth Sui package and its dependencies.
Pyth stores prices off-chain to minimize gas fees, which allows us to offer a wider selection of products and faster update times.
32
-
See [Pull Updates](../pythnet-price-feeds/pull-updates) for more information about this approach.
33
-
Typically, to use Pyth prices on chain,
34
-
they must be fetched from the [Hermes API](https://hermes.pyth.network/docs). The `SuiPriceServiceConnection` class can be used to interact with these services,
35
-
providing a way to fetch these prices directly in your code. The following example wraps an existing RPC provider and shows how to obtain
Your Sui Move module **should NOT** have a hard-coded call to `pyth::update_single_price_feed.` In other words, a contract should **never call** the Sui Pyth `pyth::update_single_price_feed` entry point. Instead, it should be called directly from client code (e.g., Typescript or Rust).
58
66
59
-
### ⚠️ **_Important Note for Integrators_**
67
+
This is because the new address differs from the original when a Sui contract is [upgraded](https://docs.sui.io/build/package-upgrades). If your module has a hard-coded call to `pyth::update_single_price_feed` living at a fixed call-site, it may eventually get bricked due to how Pyth upgrades are implemented. (We only allow users to interact with the most recent package version forsecurity reasons).
60
68
61
-
Your Sui Move module **should NOT** have a hard-coded call to `pyth::update_single_price_feed`. In other words, the Sui Pyth `pyth::update_single_price_feed` entry point should never be called by a contract, instead it should be called directly from client code (e.g. Typescript or Rust).
69
+
Therefore, you should build a [Sui programmable transaction](https://docs.sui.io/build/prog-trans-ts-sdk) that first updates the price by calling `pyth::update_single_price_feed` at the latest call-site from the client-side and then call a functionin your contract that invokes `pyth::get_price` on the `PriceInfoObject` to get the recently updated price.
70
+
You can use `SuiPythClient` to build such transactions and handle all the complexity of updating the price feeds.
62
71
63
-
This is because when a Sui contract is [upgraded](https://docs.sui.io/build/package-upgrades), the new address is different from the original. If your module has a hard-coded call to `pyth::update_single_price_feed` living at a fixed call-site, it may eventually get bricked due to the way Pyth upgrades are implemented. (We only allows users to interact with the most recent package version for security reasons).
72
+
Consult [Fetch Price Updates](../fetch-price-updates) for more information on how to fetch the `pyth_price_update`.
64
73
65
-
Therefore, you should build a [Sui programmable transaction](https://docs.sui.io/build/prog-trans-ts-sdk) that first updates the price by calling `pyth::update_single_price_feed` at the latest call-site from the client-side and then call a function in your contract that invokes `pyth::get_price` on the `PriceInfoObject` to get the recently updated price.
66
-
You can use `SuiPythClient` to build such transactions and handles all the complexity of updating the price feeds.
74
+
</Callout>
67
75
68
-
### Update Example
76
+
The code snippet below provides an example of how to update the Pyth price feeds:
[This example](./src/examples/SuiRelay.ts) shows how to update prices on an Sui network. It does the following:
168
+
[This example](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/sui/cli) shows how to update prices on a Sui network. It does the following:
211
169
212
170
1. Fetches update data from Hermes for the given price feeds.
213
-
2. Calls the Pyth Sui contract with the update data.
171
+
1. Call the Pyth Sui contract with a price update.
214
172
215
-
You can run this example with `npm run example-relay`. A full command that updates prices on Sui testnet looks like:
173
+
You can run this example with `npm run example-relay`. A full command that updates prices on the Sui testnet looks like this:
216
174
217
175
```bash
218
176
export SUI_KEY=YOUR_PRIV_KEY;
@@ -223,46 +181,13 @@ npm run example-relay -- --feed-id "5a035d5440f5c163069af66062bac6c79377bf88396f
0 commit comments