Getting price feeds off-chain via Pyth Network Price Feed Program Addresses

I am following this example eth_price Just wondering how to get the program addresses (Pyth Network) in general for an offchain application ? It seems the PDA is dervied from the feed id and shard id. I can get the feed id, but don’t know if i can get the shard id. Is there a way where i can achieve this ?

  • Either getting shard id some how so i can derive the program address from shard id + feed id
  • Or directly the program address on pythnet via some API

Any direction would really be helpful ! Thank you !

gm,

Thanks for your question.

For an off-chain application we recommend you use Hermes as explained in the docs.

What is the motivation for reading prices from Pythnet directly?

Thank you for the reply. The idea was to use existing Rust SDK available.

The Rust SDK Repo says, “utilities for reading price feeds from the pyth.network oracle in on- and off-chain applications.” . The off chain approach, consists of reading the program address and hence the question.

However, if hermes is the desired approach, I don’t see any other option, but to write my own Hermes Client in Rust.

1 Like

I would recommend that you write your own Hermes client. The API of Hermes is simple and designed for this kind of usecase.

Don’t think Open API Generator serves the purpose. One of the main API that helps is SSE.

Open API does not support SSE at the moment.

Thanks this helps. Just out of curiosity ! Is it the case that one should be using Hermes Server only for accessing data off-chain . Can’t i connect to Pyth Network RPC (one that is spunned along with publisher’s Pyth validator).

I understand that if i connect to the Pyth Network RPC, i would have to go through product account structure and can then fetch the price feed program address.

This avoids one more network hop which the Hermes Server does.

What problems do you see me encountering if i go down this route ?

If saving one network hop is crucial you can do that.

The price account addresses on Pythnet are the price feed ids in base58.

2 Likes

Just in case anyone runs into this situation.

use alloy::hex;

fn main() {
    let feed_id = hex::decode("0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace")
        .unwrap();

    let program_address = bs58::encode(feed_id).into_string();
    println!("Program Address: {}", program_address);
}

Should give you

Program Address: JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB

Thank you for all the help!

2 Likes