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
Copy file name to clipboardExpand all lines: pages/lazer/integrate-as-consumer/evm.mdx
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,31 @@ This guide is intended to serve users who wants to consume prices from the Pyth
6
6
7
7
Integrating with Pyth Lazer in smart contracts as a consumer is a three-step process:
8
8
9
-
1.**Use** Pyth Lazer SDK into EVM smart contracts to parse the price updates.
9
+
1.**Use** Pyth Lazer SDK in EVM smart contracts to parse the price updates.
10
10
2.**Subscribe** to Pyth Lazer websocket to receive price updates on backend or frontend.
11
11
3.**Include** the price updates into the smart contract transactions.
12
12
13
13
<Steps>
14
14
15
-
### Use Pyth Lazer SDK into smart contracts
15
+
### Use Pyth Lazer SDK in smart contracts
16
16
17
-
Pyth Lazer provides a [solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/contracts/evm), which allows consumers to parse the price updates.
17
+
Pyth Lazer provides a [Solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/contracts/evm), which allows consumers to parse the price updates.
18
18
19
19
```bash copy
20
-
forge install pythnet/pyth-crosschain
20
+
forge install pyth-network/pyth-crosschain
21
21
```
22
22
23
23
Add the following to `requirements.txt{:js}` file:
Once the SDK is installed, one can import the sdk into smart contracts:
30
30
31
31
```solidity copy
32
-
import { PythLazer } from "pyth-lazer/PythLazer.sol";
33
-
import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
32
+
import { PythLazer } from "pyth-lazer-sdk/PythLazer.sol";
33
+
import { PythLazerLib } from "pyth-lazer-sdk/PythLazerLib.sol";
34
34
35
35
```
36
36
@@ -127,7 +127,7 @@ for (uint8 i = 0; i < feedsLen; i++) {
127
127
128
128
### Subscribe to Pyth Lazer to receive Price Updates
129
129
130
-
Pyth Lazer provides a websocket endpoint to receive price updates. Moreover, Pyth Lazer also provides a [typescript SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to subscribe to the websocket endpoint.
130
+
Pyth Lazer provides a websocket endpoint to receive price updates. Moreover, Pyth Lazer also provides a [Typescript SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to subscribe to the websocket endpoint.
131
131
132
132
Consult [How to fetch price updates from Pyth Lazer](../fetch-price-updates.mdx) for a complete step-by-step guide.
Copy file name to clipboardExpand all lines: pages/lazer/integrate-as-consumer/svm.mdx
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Integrating with Pyth Lazer in smart contracts as a consumer is a three-step pro
12
12
13
13
<Steps>
14
14
15
-
### Use Pyth Lazer SDK into smart contracts
15
+
### Use Pyth Lazer SDK in smart contracts
16
16
17
17
Pyth Lazer provides a [Solana SDK](https://docs.rs/pyth-lazer-solana-contract/latest/pyth_lazer_solana_contract/), which allows consumers to parse and verify the price updates on Solana-compatible chains.
18
18
@@ -174,7 +174,7 @@ if data.feeds.is_empty() || data.feeds[0].properties.is_empty() {
174
174
}
175
175
```
176
176
177
-
Now you can update the state accourding to the contract's logic.
177
+
Now you can update the state according to the contract's logic:
# How to Subscribe to Price Updates from Pyth Lazer
4
4
5
-
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and channels that one can use to customize the price updates.
5
+
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and configuration options to customize the price updates.
6
6
7
7
Subscribing to price updates is a three-step process:
8
8
9
9
1.**Acquire** an access token.
10
-
2.**Adjust** subscription parameters.
10
+
2.**Configure** subscription parameters.
11
11
3.**Subscribe** to the price updates via [websocket API](https://pyth-lazer.dourolabs.app/docs).
12
12
13
13
The websocket server is available at `wss://pyth-lazer.dourolabs.app/v1/stream{:bash}`.
@@ -20,11 +20,13 @@ Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team
20
20
21
21
Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value `Bearer {token}{:bash}`.
22
22
23
-
### 2. Adjust subscription parameters
23
+
### 2. Configure subscription parameters
24
24
25
-
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below:
25
+
Lazer supports several request/subscription parameters to customize the received price updates.
26
+
These parameters are configured by sending a subscription message to the webservice.
27
+
A sample request (using the Lazer SDK client -- see step 3) is shown below:
26
28
27
-
```js
29
+
```js copy
28
30
client.send({
29
31
type:"subscribe",
30
32
subscriptionId:1,
@@ -35,64 +37,64 @@ client.send({
35
37
});
36
38
```
37
39
38
-
Here:
40
+
The most significant parameters are:
39
41
40
-
-`subscriptionId` is an arbitrary numeric identifier one can choose for a subscription. It will be returned back in response by the server. It doesn not affect the signed payload.
41
-
-`priceFeedIds` is the list of price feeds one like to receive. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds.
42
-
-`properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
43
-
-`chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc.
44
-
-`channel`allows to configure the update rate: updates in the **real_time** channel are sent as frequently as possible, while **fixed_rate@200ms** and **fixed_rate@50ms** channels are updated at fixed rates.
42
+
-`subscriptionId` is an arbitrary numeric identifier for a subscription. It will be returned back in response by the server. It does not affect the signed payload.
43
+
-`priceFeedIds` is the list of price feeds to receive updates for. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds.
44
+
-`properties` is the list of properties to retrieve, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
45
+
-`chains` is the list of chains to receive a signed payload for, such as **evm**, **solana**, etc.
46
+
-`channel`determines the update rate: updates in the **real_time** channel are sent as frequently as possible, while **fixed_rate@200ms** and **fixed_rate@50ms** channels are updated at fixed rates.
45
47
46
-
There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
48
+
There are also a few other configuration parameters -- see the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
49
+
50
+
Determine the most suitable values for your application -- they will be used in the next step.
47
51
48
52
### 3. Subscribe to the price updates
49
53
50
-
To subscribe to the price updates, one needs to send the request to the websocket server. The server will respond with a signed price update.
54
+
To subscribe to the price updates, send a request to the websocket server. The server will respond with a signed price update.
51
55
52
-
1. Pyth Lazer provides a[SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application.
53
-
It can be installed using the following command:
56
+
1. Pyth Lazer provides an[SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application.
57
+
Install it using the following command:
54
58
55
-
```bash
59
+
```bash copy
56
60
npm install --save @pythnetwork/pyth-lazer-sdk
57
61
```
58
62
59
-
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step.
63
+
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step:
3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates.
71
-
72
-
```js
73
-
client.ws.addEventListener("open", () => {
74
-
client.send({
75
-
type:"subscribe",
76
-
subscriptionId:1,
77
-
priceFeedIds: [1, 2],
78
-
properties: ["price"],
79
-
chains: ["solana"],
80
-
channel:"fixed_rate@200ms",
81
-
});
74
+
3. After the client is created, subscribe to updates (using the configuration parameters from step 2):
75
+
76
+
```js copy
77
+
client.subscribe({
78
+
type:"subscribe",
79
+
subscriptionId:1,
80
+
priceFeedIds: [1, 2],
81
+
properties: ["price"],
82
+
chains: ["solana"],
83
+
channel:"fixed_rate@200ms",
82
84
});
83
85
```
84
86
85
-
4.One the connection is established, the server will start sending the price updates to the client.
87
+
4.Once the connection is established, the server will start sending the price updates to the client:
86
88
87
-
```js
89
+
```js copy
88
90
client.addMessageListener((message) => {
89
91
console.log(message);
90
92
});
91
93
```
92
94
93
95
By default, price updates contain the `parsed` field that one can use to easily interpret the price update in their backend or frontend, as well as `evm` and/or `solana` fields that contain data that one should include in the on-chain transaction:
0 commit comments