Read a Pyth price feed account and log price, confidence, and exponent.
See also: Pyth overview and the repository catalog.
Note
The official pyth-solana-receiver-sdk is not Anchor 1.0 compatible (as of June 2026), so this example vendors the PriceUpdateV2 account type instead of importing it.
The latest pyth-solana-receiver-sdk (1.2.0) builds against anchor-lang 0.32 and pulls pythnet-sdk (2.3.1), which still derives borsh 0.10 on PriceFeedMessage. Anchor 0.32's AnchorSerialize/AnchorDeserialize derives require borsh 1.x, so pyth-solana-receiver-sdk's own PriceUpdateV2 fails to compile:
error[E0277]: the trait bound `pythnet_sdk::messages::PriceFeedMessage: BorshSerialize` is not satisfied
No published pyth-solana-receiver-sdk targets anchor-lang 1.0 (which this repo standardizes on), and no pythnet-sdk release has migrated to borsh 1.x - so the dependency can't simply be upgraded. Tracked upstream at pyth-network/pyth-crosschain#3756.
As a workaround, programs/pythexample/src/lib.rs mirrors the onchain PriceUpdateV2 layout locally (same fields, same 8-byte discriminator, owned by the Pyth Receiver program) so accounts written by Pyth deserialize unchanged. Replace the vendored type with the SDK import once an Anchor 1.0 / borsh 1.x compatible release ships.
- Oracle price accounts
- Consuming external onchain data in a program
- Oracle account validation:
Account<PriceUpdateV2>enforces that the price account is owned by the Pyth Receiver program (rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ) - Price freshness:
read_pricerejects updates older thanMAXIMUM_PRICE_AGE_SECONDS(compared againstpublish_time, a unix timestamp in seconds, mirroring the SDK'sget_price_no_older_than)
From this directory (basics/pyth/anchor/):
pnpm install
anchor buildPrerequisites: Agave CLI (version in Anchor.toml [toolchain]), Anchor, and pnpm.
Tests run in-process with LiteSVM. No local validator.
pnpm testThis runs cargo test as configured in Anchor.toml. Tests call instruction handlers and check onchain state.
Read the program programs/ source and Anchor.toml for deployed program IDs. For deployment, use anchor build && anchor deploy against your target cluster.