Skip to content

Commit ab0dead

Browse files
committed
fixes
1 parent 79796a1 commit ab0dead

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

pages/lazer/getting-started.mdx

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ import { Callout, Steps } from "nextra/components";
22

33
# Getting Started with Pyth Lazer
44

5-
Pyth Lazer is a high-performance, low-latency price feed service that provides real-time financial market data to blockchain applications. This guide will walk you through setting up and running a basic JavaScript example to subscribe to Lazer price feeds.
6-
7-
## What You'll Learn
8-
9-
In this guide, you'll learn how to:
10-
11-
- Set up the Pyth Lazer JavaScript SDK
12-
- Connect to the Lazer WebSocket stream
13-
- Subscribe to real-time price feeds
14-
- Handle both JSON and binary message formats
5+
Pyth Lazer is a high-performance, low-latency service that provides real-time financial market data.
6+
This guide will walk you through setting up and running a basic JavaScript example to subscribe to Lazer price feeds.
157

168
## Prerequisites
179

@@ -41,11 +33,7 @@ Install the required dependencies using pnpm:
4133
pnpm install
4234
```
4335

44-
This will install the following key packages:
45-
46-
- `@pythnetwork/pyth-lazer-sdk` - The main Lazer SDK
47-
- `@solana/web3.js` - For Solana blockchain interactions
48-
- Other supporting dependencies
36+
This will install `@pythnetwork/pyth-lazer-sdk`, which is the main Lazer SDK.
4937

5038
### Configure Your Access Token
5139

@@ -69,13 +57,44 @@ Now you can run the basic example that demonstrates connecting to Lazer and rece
6957
pnpm run start
7058
```
7159

72-
This will execute the main example script that:
60+
This command will subscribe to Pyth Lazer updates for two price feeds, receiving streaming updates.
61+
Each update is then printed to the terminal on receipt.
62+
You should see output similar to the following:
7363

74-
- Connects to the Pyth Lazer WebSocket server
75-
- Subscribes to price feeds (IDs 1 and 2)
76-
- Listens for both JSON and binary messages
77-
- Displays received price data and connection status
78-
- Automatically shuts down after 10 seconds
64+
```
65+
got message: {
66+
type: 'json',
67+
value: {
68+
type: 'streamUpdated',
69+
subscriptionId: 1,
70+
parsed: { timestampUs: '1758034015200000', priceFeeds: [Array] },
71+
solana: {
72+
encoding: 'hex',
73+
data: 'b9011a82036df6ced259a33949ab9b2c48a61a2d3b0b9436cba24c3ef8a600b72767927d14a459fcc3abce280b3f8194e16e8b32f9322ac0b84a9c0b792e19857962a60180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79300a3fa30ec3e060003020100000001009053802f790a00000200000001004234106d67000000'
74+
}
75+
}
76+
}
77+
stream updated for subscription 1 : [
78+
{ priceFeedId: 1, price: '11515604259728' },
79+
{ priceFeedId: 2, price: '444211409986' }
80+
]
81+
got message: {
82+
type: 'json',
83+
value: {
84+
type: 'streamUpdated',
85+
subscriptionId: 1,
86+
parsed: { timestampUs: '1758034015400000', priceFeeds: [Array] },
87+
solana: {
88+
encoding: 'hex',
89+
data: 'b9011a826f5ff7e25ac4056c4ec3a08c428baf38e7b78c46014296ccbcfd5395c38c9f7bc23865a048401c66788e791f0edc3a6701b0ea4a5399f50ec8b1795757854f0180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79340b0fd30ec3e060003020100000001005821a32f790a00000200000001004334106d67000000'
90+
}
91+
}
92+
}
93+
stream updated for subscription 1 : [
94+
{ priceFeedId: 1, price: '11515606540632' },
95+
{ priceFeedId: 2, price: '444211409987' }
96+
]
97+
```
7998

8099
### Understanding the Code
81100

@@ -89,6 +108,12 @@ const client = await PythLazerClient.create({
89108
token: process.env.ACCESS_TOKEN!,
90109
});
91110

111+
// The message listener is called every time a new message is received.
112+
client.addMessageListener((message) => {
113+
// Add your logic to consume messages here
114+
console.log("got message:", message);
115+
});
116+
92117
// Subscribe to price feeds
93118
client.subscribe({
94119
type: "subscribe",
@@ -102,38 +127,29 @@ client.subscribe({
102127
});
103128
```
104129

105-
Key concepts:
106-
107-
- **PythLazerClient**: The main client for connecting to Lazer
108-
- **Subscription**: Defines which price feeds and properties you want to receive
109-
- **Message Listeners**: Handle incoming price updates and connection events
110-
- **Channels**: Control update frequency (e.g., "fixed_rate@200ms")
111-
112130
</Steps>
113131

114132
## What's Next?
115133

116134
Now that you've successfully run the basic Lazer example, you can explore more advanced integration patterns:
117135

136+
### More Information
137+
138+
Explore additional Lazer capabilities:
139+
140+
- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling
141+
- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers
142+
118143
### Blockchain Integration
119144

120145
Learn how to integrate Lazer price feeds into your smart contracts:
121146

122147
- **[Solana Integration](./integrate-as-consumer/svm)** - Build SVM smart contracts that consume Lazer price feeds with cryptographic verification
123148
- **[EVM Integration](./integrate-as-consumer/evm)** - Integrate Lazer into Ethereum and other EVM-compatible chains
124149

125-
### Advanced Features
126-
127-
Explore additional Lazer capabilities:
128-
129-
- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling
130-
- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers
131-
- **[Acquire Access Token](./acquire-access-token)** - How to obtain and manage your Lazer access credentials
132-
133150
### Example Applications
134151

135152
Check out more comprehensive examples in the [pyth-examples repository](https://github.com/pyth-network/pyth-examples/tree/main/lazer):
136153

137154
- **Solana Examples** - Post price data to Solana smart contracts with Ed25519 and ECDSA verification
138155
- **EVM Examples** - Smart contract integration for Ethereum-compatible chains
139-
- **Publisher Examples** - Learn how to publish your own price data to Lazer

0 commit comments

Comments
 (0)