1

Hey I am working on a product that helps users analyze their solana transactions for tax purposes. I am wondering if there is a reliable way to tell who is the sender/from and who is the receiver/to in a transaction. I am thinking the easiest way to do this would be to look at the changes in the postBalance/preBalance and postTokenBalance/preTokenBalance, but is there another way like analyzing the instructions? What would be the ideal way to reliably get this information?

1 Answer 1

1

in transaction.message you can find accountKeys those are the accounts for the postBalance and preBalance in order. This means the first preBalance and postBalance are for the first account in accountKeys.

example

doing this in rust, but it's gonna be similar in typescript since they both invoke the Solana JSON RPC API.

{
account_keys: [
    ParsedAccount {
        pubkey:  "9FunJaYzY97hcTNN95mAn8iEhXQjw9NpKDmng8NYLAbt",
        writable: true,
        signer: true 
    },
    ParsedAccount {
        pubkey: "CXFCTHyuhcJL3fiFR5eRochz4k9dwzZWfLMU7knzaCp",
        writable: true,
        signer: false
    }],
}
2
  • Yes that makes sense so basically the change in balance (post - pre) that is positive is the receiver and the change in balance that is the negative is the sender? Commented Aug 31, 2022 at 17:11
  • 1
    Yes that's correct
    – vicyyn
    Commented Aug 31, 2022 at 17:15

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.