1

When using the solana-rpc-client in Rust to retrieve a transaction, the output is EncodedTransactionWithStatusMeta.

The metadata includes the following struct:

pub struct UiTransactionTokenBalance {
    pub account_index: u8,
    pub mint: String,
    pub ui_token_amount: UiTokenAmount,
    pub owner: OptionSerializer<String>,
    pub program_id: OptionSerializer<String>,
}

I'm wondering how to convert the account_index field (see UiTransactionTokenBalance into an address. Is this possible using just the transaction metadata, for example, by using loaded_addresses (refer to UiTransactionStatusMeta), or is it necessary to decode the transaction data?

Additionally, is there a way to obtain TransactionWithStatusMeta using the JSON RPC API or another protocol? What would be much pleasant to use.

1 Answer 1

1

If you want the account index, you'll need to dig into the EncodedTransaction, since none of the fields in the meta will give you the right thing. The loaded_addresses refer to addresses that were loaded from an address-lookup-table https://solana.com/docs/advanced/lookup-tables

So to get the addresses from the encoded JSON parsed tx, you'll need to do:

let accounts = match tx.encoded_transaction {
    EncodedTransaction::Json(ui_transaction) => match ui_transaction.message {
        UiMessage::Parsed(parsed_message) => parsed_message.account_keys.map(|k| k.pubkey).collect::<Vec<_>>(),
        UiMessage::Raw(raw_message) => raw_message.account_keys
    }
    _ => panic!()
};

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.