From ad0e97bf7cce088f0df88c54b22f1b0e6e5b2338 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Fri, 12 Sep 2025 09:39:40 -0700 Subject: [PATCH 1/2] tidy up --- lazer/js/README.md | 113 ++++++++++++++++++ lazer/js/package.json | 6 +- lazer/js/src/index.ts | 4 +- .../src/{publish.ts => solana/post_solana.ts} | 6 +- .../src/{ => solana}/verify_ecdsa_message.ts | 0 .../{ => solana}/verify_ed25519_message.ts | 0 6 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 lazer/js/README.md rename lazer/js/src/{publish.ts => solana/post_solana.ts} (96%) rename lazer/js/src/{ => solana}/verify_ecdsa_message.ts (100%) rename lazer/js/src/{ => solana}/verify_ed25519_message.ts (100%) diff --git a/lazer/js/README.md b/lazer/js/README.md new file mode 100644 index 0000000..a24ce09 --- /dev/null +++ b/lazer/js/README.md @@ -0,0 +1,113 @@ +# Pyth Lazer JavaScript SDK Examples + +This directory contains JavaScript/TypeScript examples demonstrating how to use the Pyth Lazer SDK to interact with real-time price feeds and verify cryptographic messages on the Solana blockchain. + +## What is Pyth Lazer? + +Pyth Lazer is a high-performance, low-latency price feed service that provides real-time financial market data to blockchain applications. It supports multiple blockchain networks and offers both JSON and binary message formats for optimal performance. + +## Prerequisites + +Before running these examples, make sure you have the following installed: + +- **Node.js** (version 18 or higher) +- **pnpm** package manager +- A Lazer Access Token -- please see the TODO. + +## Installation + +1. Navigate to the `lazer/js` directory: + ```bash + cd lazer/js + ``` + +2. Install dependencies: + ```bash + pnpm install + ``` +3. Configure your access token: + ```bash + export ACCESS_TOKEN=your_actual_token + ``` + +## Basic Examples + +### 1. WebSocket Client Example (`src/index.ts`) +Demonstrates how to connect to the Pyth Lazer WebSocket stream and receive real-time price feed updates. + +**What it does:** +- Connects to the Pyth Lazer server +- Subscribes to price feeds (IDs 1 and 2) +- Listens for both JSON and binary messages +- Displays received price data and connection status + +**How to run:** +```bash +pnpm run start +``` + +## Solana Examples + +### Prerequisites + +The Solana examples require a funded Solana private key stored in `./keypair.json`. + +### 1. Post Solana Example (`src/solana/post_solana.ts`) +Shows how to receive price data from Pyth Lazer and post it to a Solana smart contract. + +**What it does:** +- Connects to Pyth Lazer and receives price feed data +- Creates cryptographic instructions for Solana +- Posts the price data to a deployed smart contract +- Handles transaction confirmation + +**How to run:** +```bash +pnpm run start:post_solana +``` + +### 2. ECDSA Message Verification (`src/solana/verify_ecdsa_message.ts`) +Demonstrates how to verify ECDSA-signed messages using the Pyth Lazer Solana contract. + +**What it does:** +- Takes a hex-encoded message as input +- Verifies the message using ECDSA signature verification +- Interacts with the Pyth Lazer Solana program + +**How to run:** +```bash +pnpm run start:verify_ecdsa_message \ + --url 'https://api.devnet.solana.com' \ + --keypair-path './keypair.json' \ + --message "e4bd474dda8934550d660e6ef4ee6ec1557349e283090c0107cad8bb997e67783a68be5646a5c949a8deaa6bee6ec1fc8aceb5002d6808b1da8ce5e9d26fd1b56ebeaf9d001c0075d3c793403ab1a9b03706000301010000000100eaf83297b5090000" +``` + +### 3. Ed25519 Message Verification (`src/solana/verify_ed25519_message.ts`) +Shows how to verify Ed25519-signed messages using the Pyth Lazer Solana contract. + +**What it does:** +- Takes a hex-encoded message as input +- Creates Ed25519 verification instructions +- Verifies the message using the Pyth Lazer Solana program + +**How to run:** +```bash +pnpm run start:verify_ed25519_message \ + --url 'https://api.testnet.solana.com' \ + --keypair-path './keypair.json' \ + --message "b9011a82f3c5c2760beb0c78827c75b0b18f1d4a2dcddf9d3efb291e66de25927538deffd74606de833eff236022aaca7b8a79cf15d3c7b51a91b500b2b9e6ca64bcfa03f65210bee4fcf5b1cee1e537fabcfd95010297653b94af04d454fc473e94834f1c0075d3c793c03c26adb03706000301010000000100aa749416b4090000" +``` + +## Troubleshooting + +### Common Issues + +1. **Connection Errors**: Make sure you have a stable internet connection and the Pyth Lazer service is accessible. + +2. **Solana Transaction Failures**: Ensure your wallet has sufficient SOL for transaction fees and the correct network is configured. + +3. **Keypair Issues**: Make sure your Solana keypair file is in the correct format (JSON array of numbers) and the path is correct. + +## License + +This project is licensed under the Apache-2.0 License. diff --git a/lazer/js/package.json b/lazer/js/package.json index 280a819..cf5d4ec 100644 --- a/lazer/js/package.json +++ b/lazer/js/package.json @@ -6,9 +6,9 @@ "type": "module", "scripts": { "start": "node --loader ts-node/esm src/index.js", - "start:publish": "node --loader ts-node/esm src/publish.js", - "start:verify_ecdsa_message": "node --loader ts-node/esm src/verify_ecdsa_message.js", - "start:verify_ed25519_message": "node --loader ts-node/esm src/verify_ed25519_message.js", + "start:post_solana": "node --loader ts-node/esm src/solana/post_solana.js", + "start:verify_ecdsa_message": "node --loader ts-node/esm src/solana/verify_ecdsa_message.js", + "start:verify_ed25519_message": "node --loader ts-node/esm src/solana/verify_ed25519_message.js", "test": "pnpm run test:format && pnpm run test:types && pnpm run build:cjs && pnpm run build:esm", "build:cjs": "tsc --project tsconfig.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json", "build:esm": "tsc --project tsconfig.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json", diff --git a/lazer/js/src/index.ts b/lazer/js/src/index.ts index 0a40b30..d83da62 100644 --- a/lazer/js/src/index.ts +++ b/lazer/js/src/index.ts @@ -2,8 +2,8 @@ import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; const main = async () => { const client = await PythLazerClient.create({ - urls: ["wss://pyth-lazer-staging.dourolabs.app/v1/stream"], - token: "my_token", + urls: ["wss://pyth-lazer.dourolabs.app/v1/stream"], + token: process.env.ACCESS_TOKEN!, }); client.addMessageListener((message) => { diff --git a/lazer/js/src/publish.ts b/lazer/js/src/solana/post_solana.ts similarity index 96% rename from lazer/js/src/publish.ts rename to lazer/js/src/solana/post_solana.ts index 7823066..35be4f6 100644 --- a/lazer/js/src/publish.ts +++ b/lazer/js/src/solana/post_solana.ts @@ -15,7 +15,7 @@ import { SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js"; const SOLANA_RPC_URL = "https://api.devnet.solana.com"; const PAYER_SECRET_KEY = Uint8Array.from( - JSON.parse(fs.readFileSync("/path/to/private-key.json", "utf8")) as number[], + JSON.parse(fs.readFileSync("./keypair.json", "utf8")) as number[], ); // Program ID of the example contract on devnet const PROGRAM_ID = "HU64YGK66e1wdxD83D3snGuZEvfhM4YDdYShTfQvf6nm"; @@ -35,8 +35,8 @@ const connection = new Connection(SOLANA_RPC_URL, "confirmed"); const payer = Keypair.fromSecretKey(PAYER_SECRET_KEY); const main = async () => { const client = await PythLazerClient.create({ - urls: ["wss://pyth-lazer-staging.dourolabs.app/v1/stream"], - token: "my_token", + urls: ["wss://pyth-lazer.dourolabs.app/v1/stream"], + token: process.env.ACCESS_TOKEN!, }); // data received from pyth lazer diff --git a/lazer/js/src/verify_ecdsa_message.ts b/lazer/js/src/solana/verify_ecdsa_message.ts similarity index 100% rename from lazer/js/src/verify_ecdsa_message.ts rename to lazer/js/src/solana/verify_ecdsa_message.ts diff --git a/lazer/js/src/verify_ed25519_message.ts b/lazer/js/src/solana/verify_ed25519_message.ts similarity index 100% rename from lazer/js/src/verify_ed25519_message.ts rename to lazer/js/src/solana/verify_ed25519_message.ts From e9debc559d6a594e0991c2f037e0ea77d04002ce Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Fri, 12 Sep 2025 10:19:39 -0700 Subject: [PATCH 2/2] docs --- lazer/js/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lazer/js/README.md b/lazer/js/README.md index a24ce09..9a21936 100644 --- a/lazer/js/README.md +++ b/lazer/js/README.md @@ -1,6 +1,6 @@ # Pyth Lazer JavaScript SDK Examples -This directory contains JavaScript/TypeScript examples demonstrating how to use the Pyth Lazer SDK to interact with real-time price feeds and verify cryptographic messages on the Solana blockchain. +This directory contains JavaScript/TypeScript examples demonstrating how to use the Pyth Lazer SDK to interact with real-time price feeds and verify price updates on the Solana blockchain. ## What is Pyth Lazer? @@ -12,7 +12,7 @@ Before running these examples, make sure you have the following installed: - **Node.js** (version 18 or higher) - **pnpm** package manager -- A Lazer Access Token -- please see the TODO. +- A Lazer Access Token -- please see [How to Acquire an Access Token](https://docs.pyth.network/lazer/acquire-access-token) if you don't have one. ## Installation @@ -33,7 +33,7 @@ Before running these examples, make sure you have the following installed: ## Basic Examples ### 1. WebSocket Client Example (`src/index.ts`) -Demonstrates how to connect to the Pyth Lazer WebSocket stream and receive real-time price feed updates. +Demonstrates how to connect to the Pyth Lazer WebSocket stream and receive real-time price updates. **What it does:** - Connects to the Pyth Lazer server