Error loading @pythnetwork/pyth-solana-receiver due to rpc-websockets dependency conflict

:pushpin: Chain: Solana mainnet
:stopwatch: Timestamp: August 4, 2025 – 19:24 IST (13:54 UTC)
:test_tube: Steps to Reproduce:

  1. Set up a Solana TypeScript test project using Pyth SDKs.

  2. Install @pythnetwork/pyth-solana-receiver.

  3. Try running a test file using ts-mocha.

When executing a test that imports PythSolanaReceiver, we encounter the following error:

Error: Package subpath './dist/lib/client' is not defined by "exports" in /node_modules/rpc-websockets/package.json

This seems to originate from a transitive dependency inside @pythnetwork/solana-utils, which in turn is used by pyth-solana-receiver.

:receipt: Relevant Code Snippet:

import { PythSolanaReceiver } from "@pythnetwork/pyth-solana-receiver";

async function getPriceFeedAccount(feedId: string, connection: Connection, wallet: Keypair): Promise<PublicKey> {
  try {
    // Create PythSolanaReceiver instance
    const pythSolanaReceiver = new PythSolanaReceiver({ 
      connection, 
      wallet: wallet as any 
    });
    
    // Get the price feed account address using shard 0
    const priceFeedAccountAddress = pythSolanaReceiver
      .getPriceFeedAccountAddress(0, feedId)
      .toBase58();
    
    const priceFeedAccount = new PublicKey(priceFeedAccountAddress);
    
    console.log("Pyth SDK - Price feed account:", priceFeedAccount.toString());
    console.log("Feed ID:", feedId);

    // Check if the account exists
    const accountInfo = await connection.getAccountInfo(priceFeedAccount);
    if (!accountInfo) {
      console.warn(`Warning: Price feed account ${priceFeedAccount.toString()} does not exist on the blockchain.`);
      console.warn("This might cause issues if the account is required for the transaction.");
    } else {
      console.log("Price feed account exists and has size:", accountInfo.data.length);
    }

    return priceFeedAccount;
  } catch (error) {
    console.error("Error getting price feed account:", error);
    throw error;
  }
}

:bullseye: Issue Summary:

  • Root cause appears to be related to rpc-websockets usage within the Pyth packages (possibly inside jito-ts or @pythnetwork/solana-utils).

Any help resolving this issue or understanding the required setup would be appreciated. :folded_hands:

Gm @lokeshwaran100 !

Apologies for the delay. I’m not able to reproduce your issue, I can execute pnpm exec ts-node examples/update_price_feed.ts to run the @pythnetwork/pyth-solana-receiver examples. Can you try that?

If the issue comes from importing PythSolanaReceiver into your own test code, please provide source code snippets and output logs. It sounds like there’s some kind of compilation configuration issue going on in your setup.

Thanks!

This works. I’m looking to get the price details for different tokens, where I can have the price feed account upfront—similar to how I can get the Solana price using the 7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE price update account. Where can I find the corresponding price feed accounts for other tokens so that I can supply them directly to the program?

@lokeshwaran100 you seen this?

Docs: https://docs.pyth.network/price-feeds/price-feeds#feed-ids

Legacy website: Price Feed IDs | Pyth Network

be sure to check the dropdown on the legacy website

I am using npx-create-solana-dapp@4.6.0 scaffold for building my solana dapp,using npm@latest , where it uses Codama.js to generate client interface and then calls instructions using those interface. The test file in the new scaffold uses @solana/kit and solana-kite for testing instead of @coral-xyz/anchor and @solana/web3.js libraries.

This is my UpdateGoldTokenPrice.rs Instruction file where I want to fetch XAU/USD PriceFeed for on-chain calculations.

use crate::error::ErrorCode;
use crate::events::*;
use crate::state::*;
use anchor_lang::prelude::*;
use pyth_solana_receiver_sdk::price_update::get_feed_id_from_hex;
use pyth_solana_receiver_sdk::price_update::PriceUpdateV2;


// The instruction logic is updated to fetch the price
pub fn update_gold_price(ctx: Context<UpdateGoldPrice>) -> Result<()> {
    require!(!ctx.accounts.gold_state.is_paused, ErrorCode::ProgramPaused);
    let price_update = &mut ctx.accounts.price_update;
    let maximum_age: u64 = 30;
    let feed_id: [u8; 32] =
        get_feed_id_from_hex("765d2ba906dbc32ca17cc11f5310a89e9ee1f6420508c63861f2f8ba4ee34bb2")?;
    let current_price =
        price_update.get_price_no_older_than(&Clock::get()?, maximum_age, &feed_id)?;

    let exponent_adjustment = 10u64.pow(current_price.exponent.abs() as u32 - 2);
    let price_in_cents = (current_price.price as u64) / exponent_adjustment;

    require!(price_in_cents > 0, ErrorCode::InvalidPrice);

    let gold_state = &mut ctx.accounts.gold_state;
    gold_state.gold_price_usd = price_in_cents;
    gold_state.last_price_update = Clock::get()?.unix_timestamp;

    emit!(PriceUpdated {
        new_price: price_in_cents,
        timestamp: gold_state.last_price_update,
    });

    msg!(
        "Gold price updated to {} cents per ounce from Pyth.",
        price_in_cents
    );
    Ok(())
}

#[derive(Accounts)]
pub struct UpdateGoldPrice<'info> {
    #[account(
        mut,
        has_one = oracle_authority @ ErrorCode::UnauthorizedOracle,
    )]
    pub gold_state: Account<'info, GoldState>,

    // The admin who is authorized to trigger the price update
    pub oracle_authority: Signer<'info>,
    pub price_update: Account<'info, PriceUpdateV2>,
}

Now, how can I create a test function for the same , since the new @solana/kit works differently.

We don’t support @solana/kit in our Typescript sdks.

For this kind of testing, I recommend you add a pre-populated price_update account to your test validator and use it in your test.