What I am trying to do is listen to some onchain program accounts being changed. I could do this pretty easily in typescript with onProgramAccountChange() method provided in the Connection class in @solana/web3.js package. Is there a way to do this in rust, as I cannot find any impl in rust's solana_client crate.
1 Answer
Yes,
You have to use the PubsubClient
solana_client::{
nonblocking::pubsub_client::PubsubClient,
};
This is the method you want:
pub async fn account_subscribe(
&self,
pubkey: &Pubkey,
config: Option<RpcAccountInfoConfig>,
) -> SubscribeResult<'_, RpcResponse<UiAccount>> {
let params = json!([pubkey.to_string(), config]);
self.subscribe("account", params).await
}