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/svm.mdx
+1-122Lines changed: 1 addition & 122 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,128 +14,7 @@ Integrating with Pyth Lazer in smart contracts as a consumer is a three-step pro
14
14
15
15
### Use Pyth Lazer SDK into 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.
18
-
19
-
```bash copy
20
-
forge install pythnet/pyth-crosschain
21
-
```
22
-
23
-
Add the following to `requirements.txt{:js}` file:
Once the SDK is installed, one can import the sdk into smart contracts:
30
-
31
-
```solidity copy
32
-
import { PythLazer } from "pyth-lazer/PythLazer.sol";
33
-
import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
34
-
35
-
```
36
-
37
-
After importing the SDK, initialize the [`PythLazer`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L7) contract and set up state varables to store prices and timestamps:
38
-
39
-
```solidity copy
40
-
contract ExampleConsumer {
41
-
// Example state.
42
-
PythLazer pythLazer;
43
-
uint64 public price;
44
-
uint64 public timestamp;
45
-
46
-
//...
47
-
48
-
constructor(address pythLazerAddress) {
49
-
pythLazer = PythLazer(pythLazerAddress);
50
-
}
51
-
}
52
-
53
-
```
54
-
55
-
Add an argument of type `bytes calldata{:solidity}` to the method which will receive the Pyth Lazer price udpate:
56
-
57
-
```solidity copy
58
-
function updatePrice(bytes calldata priceUpdate) public payable {
The `verifyUpdate` function will verify the price update and return the payload and the verification fee. This call takes a fee which can be queried from [`verification_fee(){:solidity}`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L9) function and passed to the `verifyUpdate` call. This fee is used to cover the cost of verifying the price update.
67
-
68
-
This SDK provides [`parsePayloadHeader`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazerLib.sol#L21) method to retrieve the values from the payload header.
Make sure to pass the `pos` variable to every parsing call and assign the
115
-
returned `pos` value to the same variable. Failure to do so will cause
116
-
incorrect parsing results.
117
-
</Callout>
118
-
119
-
<Callouttype="warning"emoji="⚠️">
120
-
When calling these parse functions, you must not skip price feeds or
121
-
properties. Every parsing function will modify your `pos` variable, so
122
-
skipping a call of `parseFeedHeader`, `parseFeedProperty`, or
123
-
`parseFeedValueUint64` will lead to incorrect parsing results. Keep in mind
124
-
that you can customize the set of price feeds and properties when requesting
125
-
price updates via WebSocket. This will be explained in the next step.
126
-
</Callout>
127
-
128
-
### Subscribe to Pyth Lazer to receive Price Updates
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.
131
-
132
-
Consult [How to fetch price updates from Pyth Lazer](../fetch-price-updates.mdx) for a complete step-by-step guide.
133
-
134
-
### Include the price updates into smart contract transactions
135
-
136
-
Now that you have the price updates, and your smart contract is able to parse the price updates, you can include the price updates into the smart contract transactions by passing the price updates received from the previous step as an argument to the `updatePrice` method of your smart contract.
137
-
138
-
</Steps>
17
+
Pyth Lazer provides [pyth-lazer-sdk]() crate, which allows consumers to parse the price updates.
0 commit comments