I have a transaction signature for which I want to know the amount of tokens swapped. I have seen various discussions on the topic. Most of them suggest to make the JSON RPC call using the getTransaction() method and then compare the preTokenBalances and postTokenBalances. However, I can't make it work for 2 reasons:
- The format of an entry in preTokenBalances and postTokenBalances is
{
"accountIndex":,
"mint":"",
"owner":"",
"programId":"",
"uiTokenAmount":{"amount":"","decimals":,"uiAmount":,"uiAmountString":""}
}
The owner address here is quite confusing. Sometime I can find my own wallet address here. Sometimes I find the address associated with the specific token for my wallet address. Sometimes the address of the account which is transferring the tokens into my account.
- In the cases where the token swap is being done via multiple paths, the token comes into my account via multiple accounts.
For example this transaction. Can someone tell the most accurate way to get the transaction amount. How does solscan do it?