2

If I want to react to an account changing, I can use the onAccountChange function in web3.js, like described here for example. I'm building a client in rust though, does anchor_client or solana_sdk have any equivalent to this (which isn't just me manually querying the account over and over)?

1

1 Answer 1

1

Figured it out:

let listener_client = PubsubClient::new(<WSS URL>).await.unwrap();
// Can add a config instead of None here, but None for simplicity
let (stream, shutdown_handle) = listener_client.account_subscribe(&mempool, None)
    .await.unwrap();
while let Some(data) = stream.next() {
    println!("Received an update! {}",data);
}
// Stream closed


...

// Somewhere else if we want to close the websocket
shutdown_handle();

Also check out the new mango client for a more involved example, this was very helpful for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.