0

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:

  1. 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.

  1. 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?

1 Answer 1

1

Solscan does this by looking at the inner instructions of a transaction and finding all token transfer instructions.

In your example transaction, you'll find 5 token transfer inner instructions.

You can see the inner transactions in your getTransaction response, transaction.meta.innerInstructions array.

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.