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
> **DEPRECATION NOTICE:** This package is deprecated and no longer maintained. Please use [hermes-client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js) instead.
1
+
# Pyth EVM JS
5
2
6
3
[Pyth](https://pyth.network/) provides real-time pricing data in a variety of asset classes, including cryptocurrency,
7
4
equities, FX and commodities. This library allows you to use these real-time prices on EVM-based networks.
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices).
98
-
99
-
### Off-chain prices
100
-
101
-
Many applications additionally need to display Pyth prices off-chain, for example, in their frontend application.
102
-
The `EvmPriceServiceConnection` provides two different ways to fetch the current Pyth price.
103
-
The code blocks below assume that the `connection` and `priceIds` objects have been initialized as shown above.
104
-
The first method is a single-shot query:
24
+
The `fillPythUpdate` function helps you automatically determine what Pyth price updates are needed for a transaction and creates the necessary update call.
25
+
This function uses the `trace_callMany` method by default but can be used with `debug_traceCall` and a bundler as well. See the example below for more information.
105
26
106
27
```typescript
107
-
// `getLatestPriceFeeds` returns a `PriceFeed` for each price id. It contains all information about a price and has
108
-
// utility functions to get the current and exponentially-weighted moving average price, and other functionality.
`Received update for ${priceFeed.id}: ${priceFeed.getPriceNoOlderThan(60)}`
125
-
);
126
-
});
127
-
128
-
// When using the subscription, make sure to close the websocket upon termination to finish the process gracefully.
129
-
setTimeout(() => {
130
-
connection.closeWebSocket();
131
-
}, 60000);
132
-
```
133
-
134
-
### Examples
135
-
136
-
There are two examples in [examples](./src/examples/).
137
-
138
-
#### EvmPriceServiceClient
139
-
140
-
[This example](./src/examples/EvmPriceServiceClient.ts) fetches `PriceFeed` updates using both a HTTP-request API and a streaming websocket API. You can run it with `npm run example-client`. A full command that prints BTC and ETH price feeds, in the testnet network, looks like so:
0 commit comments