|
| 1 | +--- |
| 2 | +title: Getting Started |
| 3 | +description: Learn how to access, configure, and use Pyth Pro price feeds |
| 4 | +slug: /price-feeds/pro/getting-started |
| 5 | +--- |
| 6 | + |
| 7 | +import { Callout } from "fumadocs-ui/components/callout"; |
| 8 | +import { Step, Steps } from "fumadocs-ui/components/steps"; |
| 9 | + |
| 10 | +Pyth Pro is a high-performance, low-latency service that provides real-time financial market data. |
| 11 | +This guide will walk you through setting up and running a basic JavaScript example to subscribe to Pyth Pro price feeds. |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +Before getting started, make sure you have the following installed: |
| 16 | + |
| 17 | +- **Node.js** (version 18 or higher) |
| 18 | +- **pnpm** package manager |
| 19 | +- **Git** for cloning the examples repository |
| 20 | +- A **Pyth Pro Access Token** - see [How to Acquire an Access Token](./acquire-access-token) if you don't have one |
| 21 | + |
| 22 | +<Steps> |
| 23 | + <Step> |
| 24 | + ### Clone the Examples Repository |
| 25 | +First, clone the Pyth examples repository which contains the JavaScript SDK example: |
| 26 | + |
| 27 | +```bash copy |
| 28 | +git clone https://github.com/pyth-network/pyth-examples.git |
| 29 | +cd pyth-examples/lazer/js |
| 30 | +``` |
| 31 | + |
| 32 | + </Step> |
| 33 | + <Step> |
| 34 | + ### Install Dependencies |
| 35 | +Install the required dependencies using pnpm: |
| 36 | + |
| 37 | +```bash copy |
| 38 | +pnpm install |
| 39 | +``` |
| 40 | + |
| 41 | +This will install `@pythnetwork/pyth-lazer-sdk`, which will be used to subscribe to Pyth Pro prices. |
| 42 | + |
| 43 | +<Callout type="info"> |
| 44 | + **Pyth Pro was previously known as Pyth Lazer**. The SDK remains the same. |
| 45 | +</Callout> |
| 46 | + </Step> |
| 47 | + <Step> |
| 48 | + ### Configure Your Access Token |
| 49 | +Set your Pyth Pro access token as an environment variable: |
| 50 | + |
| 51 | +```bash copy |
| 52 | +export ACCESS_TOKEN=your_actual_token_here |
| 53 | +``` |
| 54 | + |
| 55 | +<Callout type="warning"> |
| 56 | + Replace `your_actual_token_here` with your actual Pyth Pro access token. If you |
| 57 | + don't have one, follow the [access token guide](./acquire-access-token) to |
| 58 | + obtain it. |
| 59 | +</Callout> |
| 60 | + </Step> |
| 61 | + <Step> |
| 62 | + ### Run the Basic WebSocket Example |
| 63 | +Now you can run the basic example that demonstrates connecting to Pyth Pro and receiving price updates: |
| 64 | + |
| 65 | +```bash copy |
| 66 | +pnpm run start |
| 67 | +``` |
| 68 | + |
| 69 | +This command will subscribe to Pyth Pro updates for two price feeds, receiving streaming updates. |
| 70 | +Each update is then printed to the terminal on receipt. |
| 71 | +You should see output similar to the following: |
| 72 | + |
| 73 | +```bash copy |
| 74 | +got message: { |
| 75 | + type: 'json', |
| 76 | + value: { |
| 77 | + type: 'streamUpdated', |
| 78 | + subscriptionId: 1, |
| 79 | + parsed: { timestampUs: '1758034015200000', priceFeeds: [Array] }, |
| 80 | + solana: { |
| 81 | + encoding: 'hex', |
| 82 | + data: 'b9011a82036df6ced259a33949ab9b2c48a61a2d3b0b9436cba24c3ef8a600b72767927d14a459fcc3abce280b3f8194e16e8b32f9322ac0b84a9c0b792e19857962a60180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79300a3fa30ec3e060003020100000001009053802f790a00000200000001004234106d67000000' |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +stream updated for subscription 1 : [ |
| 87 | + { priceFeedId: 1, price: '11515604259728' }, |
| 88 | + { priceFeedId: 2, price: '444211409986' } |
| 89 | +] |
| 90 | +got message: { |
| 91 | + type: 'json', |
| 92 | + value: { |
| 93 | + type: 'streamUpdated', |
| 94 | + subscriptionId: 1, |
| 95 | + parsed: { timestampUs: '1758034015400000', priceFeeds: [Array] }, |
| 96 | + solana: { |
| 97 | + encoding: 'hex', |
| 98 | + data: 'b9011a826f5ff7e25ac4056c4ec3a08c428baf38e7b78c46014296ccbcfd5395c38c9f7bc23865a048401c66788e791f0edc3a6701b0ea4a5399f50ec8b1795757854f0180efc1f480c5615af3fb673d42287e993da9fbc3506b6e41dfa32950820c2e6c2a0075d3c79340b0fd30ec3e060003020100000001005821a32f790a00000200000001004334106d67000000' |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +stream updated for subscription 1 : [ |
| 103 | + { priceFeedId: 1, price: '11515606540632' }, |
| 104 | + { priceFeedId: 2, price: '444211409987' } |
| 105 | +] |
| 106 | +``` |
| 107 | +
|
| 108 | + </Step> |
| 109 | + <Step> |
| 110 | + ### Understand the Example Code |
| 111 | +The main example code in `src/index.ts` demonstrates the core Pyth Pro integration pattern: |
| 112 | +
|
| 113 | +```typescript copy |
| 114 | +import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; |
| 115 | + |
| 116 | +const client = await PythLazerClient.create({ |
| 117 | + urls: [ |
| 118 | + "wss://pyth-lazer-0.dourolabs.app/v1/stream", |
| 119 | + "wss://pyth-lazer-1.dourolabs.app/v1/stream", |
| 120 | + ], |
| 121 | + token: process.env.ACCESS_TOKEN!, |
| 122 | +}); |
| 123 | + |
| 124 | +// The message listener is called every time a new message is received. |
| 125 | +client.addMessageListener((message) => { |
| 126 | + // Add your logic to consume messages here |
| 127 | + console.log("got message:", message); |
| 128 | +}); |
| 129 | +
|
| 130 | +// Subscribe to price feeds |
| 131 | +client.subscribe({ |
| 132 | + type: "subscribe", |
| 133 | + subscriptionId: 1, |
| 134 | + priceFeedIds: [1, 2], |
| 135 | + properties: ["price"], |
| 136 | + formats: ["solana"], |
| 137 | + deliveryFormat: "json", |
| 138 | + channel: "fixed_rate@200ms", |
| 139 | + jsonBinaryEncoding: "hex", |
| 140 | +}); |
| 141 | +``` |
| 142 | +
|
| 143 | +NOTE: Every property passed to `client.subscribe` are explained in the [API Reference](https://pyth-lazer.dourolabs.app/docs). |
| 144 | +
|
| 145 | + </Step> |
| 146 | +</Steps> |
| 147 | +
|
| 148 | +## What's Next? |
| 149 | +
|
| 150 | +Now that you've successfully run the basic Pyth Pro example, you can explore more advanced integration patterns: |
| 151 | +
|
| 152 | +### More Information |
| 153 | +
|
| 154 | +Explore additional Pyth Pro capabilities: |
| 155 | +
|
| 156 | +- **[Subscribe to Price Updates](./subscribe-price-updates)** - Detailed guide on WebSocket subscriptions and message handling |
| 157 | +- **[Price Feed IDs](./price-feed-ids)** - Complete list of available price feeds and their identifiers |
| 158 | +
|
| 159 | +### Blockchain Integration |
| 160 | +
|
| 161 | +Learn how to integrate Pyth Pro price feeds into your smart contracts: |
| 162 | +
|
| 163 | +- **[Solana Integration](./integrate-as-consumer/svm)** - Build SVM smart contracts that consume Pyth Pro price feeds with cryptographic verification |
| 164 | +- **[EVM Integration](./integrate-as-consumer/evm)** - Integrate Pyth Pro into Ethereum and other EVM-compatible chains |
| 165 | +
|
| 166 | +### Example Applications |
| 167 | +
|
| 168 | +Check out more comprehensive examples in the [pyth-examples repository](https://github.com/pyth-network/pyth-examples/tree/main/lazer): |
| 169 | +
|
| 170 | +- **Solana Examples** - Post price data to Solana smart contracts with Ed25519 and ECDSA verification |
| 171 | +- **EVM Examples** - Smart contract integration for Ethereum-compatible chains |
0 commit comments