1

I am monitoring swap transactions on Jupiter, but I am encountering an issue because Jupiter uses different routes for transactions each time, resulting in data appearing in different indices. Is there a way to create a generic implementation to obtain input/output addresses?

For example, if I fetch a transaction with a signature like this:

const tx = await connectionMainnet.getParsedTransaction('2v36qHKKirrp6nsP2R92SN16NDc1dtZYNtnyXAKQZNBWrQeWsRxZkAMbQcodeLfbafRjye2J3JM32VS9aEQyJeVr', {maxSupportedTransactionVersion:0 });

I am looking for a generic function that takes a transaction and returns the input/output mint addresses of the token.

Input token: Sol - So11111111111111111111111111111111111111112

Output token: USDC - EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

2 Answers 2

2

You can simply use Bitquery's Jupiter API to get the data on Swaps. You can get the Swapped tokens and the addresses involved in swapping transaction. You can also get the route that jupiter took to swap the tokens.

Try the API - https://ide.bitquery.io/Tokens-involved-in-Jupiter-swap-source-address-destination-address-DEX-involved_2#

In the response of the API, the 2nd and 3rd address in the Accounts array are the addresses which has Token B and A respectively. And 8th and 9th address in the Accounts array are the Tokens A and B respectively.

Watch a Video Tutorial- https://youtu.be/NqWzQm1zoZ8?si=uA64YVPHuYGoZCOv

Full Disclosure: I work at Bitquery.

1

Your best bet would be to look at the pre and post token balances in the transaction in preTokenBalances and postTokenBalances: https://solana.com/docs/rpc/http/gettransaction

So you want to see which user account has lost tokens (input) and which user account has gained tokens (output). You might end up getting it wrong, because the protocol inside of Jupiter is receiving the input tokens, and sending the output token.

To identify the "user" accounts, you could see if they are owned by the fee payer on the 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.