0

I am trying to fetch the events emitted in a transaction so that i can parse the data and use it on the client. But wondering on how i can fetch it on the anchor client in rust since i couldnt find any function which did that.

1 Answer 1

1

You can simply retrieve the transaction with an RPC client and read through the logs to extract events.

use solana_rpc_client::rpc_client::RpcClient;

let rpc_client = RpcClient::new(...); // your network here
let signature = // your signature
let encoded_transaction = rpc_client.get_transaction(
    &signature,
    UiTransactionEncoding::Json,
)?;
let logs = encoded_transaction.transaction.meta.unwrap().log_messages;

More information at https://docs.rs/solana-rpc-client/latest/solana_rpc_client/rpc_client/struct.RpcClient.html#method.get_transaction

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.