From 6a22dd2f82626d37b29b1147113771535862bcf8 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 12 Sep 2025 17:47:36 +0000 Subject: [PATCH 1/3] Update Lazer getting started guide with JavaScript example walkthrough - Replace minimal content with comprehensive step-by-step guide - Include prerequisites, setup instructions, and code examples - Add Next Steps section linking to SVM and EVM integration guides - Reference the JavaScript example from pyth-examples repository Co-Authored-By: Jayant --- pages/lazer/getting-started.mdx | 132 +++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/pages/lazer/getting-started.mdx b/pages/lazer/getting-started.mdx index da529c2b..eef33d93 100644 --- a/pages/lazer/getting-started.mdx +++ b/pages/lazer/getting-started.mdx @@ -1,3 +1,133 @@ +import { Callout, Steps } from "nextra/components"; + # Getting Started with Pyth Lazer -Please refer to the how-to guides to get started. +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. + +## What You'll Learn + +In this guide, you'll learn how to: +- Set up the Pyth Lazer JavaScript SDK +- Connect to the Lazer WebSocket stream +- Subscribe to real-time price feeds +- Handle both JSON and binary message formats + +## Prerequisites + +Before getting started, make sure you have the following installed: + +- **Node.js** (version 18 or higher) +- **pnpm** package manager +- **Git** for cloning the examples repository +- A **Lazer Access Token** - see [How to Acquire an Access Token](./acquire-access-token) if you don't have one + + + +### Clone the Examples Repository + +First, clone the Pyth examples repository which contains the JavaScript SDK example: + +```bash copy +git clone https://github.com/pyth-network/pyth-examples.git +cd pyth-examples/lazer/js +``` + +### Install Dependencies + +Install the required dependencies using pnpm: + +```bash copy +pnpm install +``` + +This will install the following key packages: +- `@pythnetwork/pyth-lazer-sdk` - The main Lazer SDK +- `@solana/web3.js` - For Solana blockchain interactions +- Other supporting dependencies + +### Configure Your Access Token + +Set your Lazer access token as an environment variable: + +```bash copy +export ACCESS_TOKEN=your_actual_token_here +``` + + + Replace `your_actual_token_here` with your actual Lazer access token. If you don't have one, follow the [access token guide](./acquire-access-token) to obtain it. + + +### Run the Basic WebSocket Example + +Now you can run the basic example that demonstrates connecting to Lazer and receiving price updates: + +```bash copy +pnpm run start +``` + +This will execute the main example script that: +- Connects to the Pyth Lazer WebSocket server +- Subscribes to price feeds (IDs 1 and 2) +- Listens for both JSON and binary messages +- Displays received price data and connection status +- Automatically shuts down after 10 seconds + +### Understanding the Code + +The main example code in `src/index.ts` demonstrates the core Lazer integration pattern: + +```typescript +import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; + +const client = await PythLazerClient.create({ + urls: ["wss://pyth-lazer.dourolabs.app/v1/stream"], + token: process.env.ACCESS_TOKEN!, +}); + +// Subscribe to price feeds +client.subscribe({ + type: "subscribe", + subscriptionId: 1, + priceFeedIds: [1, 2], + properties: ["price"], + formats: ["solana"], + deliveryFormat: "json", + channel: "fixed_rate@200ms", + jsonBinaryEncoding: "hex", +}); +``` + +Key concepts: +- **PythLazerClient**: The main client for connecting to Lazer +- **Subscription**: Defines which price feeds and properties you want to receive +- **Message Listeners**: Handle incoming price updates and connection events +- **Channels**: Control update frequency (e.g., "fixed_rate@200ms") + + + +## What's Next? + +Now that you've successfully run the basic Lazer example, you can explore more advanced integration patterns: + +### Blockchain Integration + +Learn how to integrate Lazer price feeds into your smart contracts: + +- **[Solana Integration](./integrate-as-consumer/svm)** - Build SVM smart contracts that consume Lazer price feeds with cryptographic verification +- **[EVM Integration](./integrate-as-consumer/evm)** - Integrate Lazer into Ethereum and other EVM-compatible chains + +### Advanced Features + +Explore additional Lazer capabilities: + +- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling +- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers +- **[Acquire Access Token](./acquire-access-token)** - How to obtain and manage your Lazer access credentials + +### Example Applications + +Check out more comprehensive examples in the [pyth-examples repository](https://github.com/pyth-network/pyth-examples/tree/main/lazer): + +- **Solana Examples** - Post price data to Solana smart contracts with Ed25519 and ECDSA verification +- **EVM Examples** - Smart contract integration for Ethereum-compatible chains +- **Publisher Examples** - Learn how to publish your own price data to Lazer From 79796a17faa8001fee5b2e4736ad76098d8657d2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 12 Sep 2025 17:54:39 +0000 Subject: [PATCH 2/3] Fix prettier formatting issues in Lazer getting started guide - Apply prettier formatting to resolve pre-commit CI failure - Add blank lines and wrap long lines per prettier rules Co-Authored-By: Jayant --- pages/lazer/getting-started.mdx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pages/lazer/getting-started.mdx b/pages/lazer/getting-started.mdx index eef33d93..f4dde3a4 100644 --- a/pages/lazer/getting-started.mdx +++ b/pages/lazer/getting-started.mdx @@ -7,6 +7,7 @@ Pyth Lazer is a high-performance, low-latency price feed service that provides r ## What You'll Learn In this guide, you'll learn how to: + - Set up the Pyth Lazer JavaScript SDK - Connect to the Lazer WebSocket stream - Subscribe to real-time price feeds @@ -41,6 +42,7 @@ pnpm install ``` This will install the following key packages: + - `@pythnetwork/pyth-lazer-sdk` - The main Lazer SDK - `@solana/web3.js` - For Solana blockchain interactions - Other supporting dependencies @@ -54,7 +56,9 @@ export ACCESS_TOKEN=your_actual_token_here ``` - Replace `your_actual_token_here` with your actual Lazer access token. If you don't have one, follow the [access token guide](./acquire-access-token) to obtain it. + Replace `your_actual_token_here` with your actual Lazer access token. If you + don't have one, follow the [access token guide](./acquire-access-token) to + obtain it. ### Run the Basic WebSocket Example @@ -66,6 +70,7 @@ pnpm run start ``` This will execute the main example script that: + - Connects to the Pyth Lazer WebSocket server - Subscribes to price feeds (IDs 1 and 2) - Listens for both JSON and binary messages @@ -98,6 +103,7 @@ client.subscribe({ ``` Key concepts: + - **PythLazerClient**: The main client for connecting to Lazer - **Subscription**: Defines which price feeds and properties you want to receive - **Message Listeners**: Handle incoming price updates and connection events From ab0dead6cf6a10c5dcbfde2f13ff8ab1fca76aad Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Tue, 16 Sep 2025 07:56:01 -0700 Subject: [PATCH 3/3] fixes --- pages/lazer/getting-started.mdx | 90 +++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/pages/lazer/getting-started.mdx b/pages/lazer/getting-started.mdx index f4dde3a4..b1a7b38d 100644 --- a/pages/lazer/getting-started.mdx +++ b/pages/lazer/getting-started.mdx @@ -2,16 +2,8 @@ import { Callout, Steps } from "nextra/components"; # Getting Started with Pyth Lazer -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. - -## What You'll Learn - -In this guide, you'll learn how to: - -- Set up the Pyth Lazer JavaScript SDK -- Connect to the Lazer WebSocket stream -- Subscribe to real-time price feeds -- Handle both JSON and binary message formats +Pyth Lazer is a high-performance, low-latency service that provides real-time financial market data. +This guide will walk you through setting up and running a basic JavaScript example to subscribe to Lazer price feeds. ## Prerequisites @@ -41,11 +33,7 @@ Install the required dependencies using pnpm: pnpm install ``` -This will install the following key packages: - -- `@pythnetwork/pyth-lazer-sdk` - The main Lazer SDK -- `@solana/web3.js` - For Solana blockchain interactions -- Other supporting dependencies +This will install `@pythnetwork/pyth-lazer-sdk`, which is the main Lazer SDK. ### Configure Your Access Token @@ -69,13 +57,44 @@ Now you can run the basic example that demonstrates connecting to Lazer and rece pnpm run start ``` -This will execute the main example script that: +This command will subscribe to Pyth Lazer updates for two price feeds, receiving streaming updates. +Each update is then printed to the terminal on receipt. +You should see output similar to the following: -- Connects to the Pyth Lazer WebSocket server -- Subscribes to price feeds (IDs 1 and 2) -- Listens for both JSON and binary messages -- Displays received price data and connection status -- Automatically shuts down after 10 seconds +``` +got message: { + type: 'json', + value: { + type: 'streamUpdated', + subscriptionId: 1, + parsed: { timestampUs: '1758034015200000', priceFeeds: [Array] }, + solana: { + encoding: 'hex', + data: 'b9011a82036df6ced259a33949ab9b2c48a61a2d3b0b9436cba24c3ef8a600b72767927d14a459fcc3abce280b3f8194e16e8b32f9322ac0b84a9c0b792e19857962a60180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79300a3fa30ec3e060003020100000001009053802f790a00000200000001004234106d67000000' + } + } +} +stream updated for subscription 1 : [ + { priceFeedId: 1, price: '11515604259728' }, + { priceFeedId: 2, price: '444211409986' } +] +got message: { + type: 'json', + value: { + type: 'streamUpdated', + subscriptionId: 1, + parsed: { timestampUs: '1758034015400000', priceFeeds: [Array] }, + solana: { + encoding: 'hex', + data: 'b9011a826f5ff7e25ac4056c4ec3a08c428baf38e7b78c46014296ccbcfd5395c38c9f7bc23865a048401c66788e791f0edc3a6701b0ea4a5399f50ec8b1795757854f0180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79340b0fd30ec3e060003020100000001005821a32f790a00000200000001004334106d67000000' + } + } +} +stream updated for subscription 1 : [ + { priceFeedId: 1, price: '11515606540632' }, + { priceFeedId: 2, price: '444211409987' } +] +``` ### Understanding the Code @@ -89,6 +108,12 @@ const client = await PythLazerClient.create({ token: process.env.ACCESS_TOKEN!, }); +// The message listener is called every time a new message is received. +client.addMessageListener((message) => { + // Add your logic to consume messages here + console.log("got message:", message); +}); + // Subscribe to price feeds client.subscribe({ type: "subscribe", @@ -102,19 +127,19 @@ client.subscribe({ }); ``` -Key concepts: - -- **PythLazerClient**: The main client for connecting to Lazer -- **Subscription**: Defines which price feeds and properties you want to receive -- **Message Listeners**: Handle incoming price updates and connection events -- **Channels**: Control update frequency (e.g., "fixed_rate@200ms") - ## What's Next? Now that you've successfully run the basic Lazer example, you can explore more advanced integration patterns: +### More Information + +Explore additional Lazer capabilities: + +- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling +- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers + ### Blockchain Integration Learn how to integrate Lazer price feeds into your smart contracts: @@ -122,18 +147,9 @@ Learn how to integrate Lazer price feeds into your smart contracts: - **[Solana Integration](./integrate-as-consumer/svm)** - Build SVM smart contracts that consume Lazer price feeds with cryptographic verification - **[EVM Integration](./integrate-as-consumer/evm)** - Integrate Lazer into Ethereum and other EVM-compatible chains -### Advanced Features - -Explore additional Lazer capabilities: - -- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling -- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers -- **[Acquire Access Token](./acquire-access-token)** - How to obtain and manage your Lazer access credentials - ### Example Applications Check out more comprehensive examples in the [pyth-examples repository](https://github.com/pyth-network/pyth-examples/tree/main/lazer): - **Solana Examples** - Post price data to Solana smart contracts with Ed25519 and ECDSA verification - **EVM Examples** - Smart contract integration for Ethereum-compatible chains -- **Publisher Examples** - Learn how to publish your own price data to Lazer