Title:
Solana: Swap API – Balance Change Not Displayed When Using Jupiter Swap API
Introduction
When working with the Solana blockchain using the Jupiter swap API, users have been facing a frustrating issue where their wallet balances do not accurately reflect the changes after swapping tokens. In this article, we’ll delve into the details of the problem and provide a solution to display balance changes in the wallet.
The Issue
The main concern here is that when creating a transaction for swapping tokens using Jupiter’s API, the balance
field in the transaction string is not updated with the new balance after the swap. This can lead to confusion among users who may not be aware of their current balance before and after the swap.
For example, let’s say you’re trying to swap 100 SOL for 50 SOL using Jupiter’s API. Initially, your wallet has 100 SOL. After swapping, you expect your new balance to be 150 SOL. However, when you sign the transaction, nothing seems to happen, and your balance does not change.
The Solution
To display the correct balance changes in your wallet, we need to update the balance
field in the transaction string using the following code snippet:
{
"method": "swap",
"params": [
{
"from": "your_account_address",
"to": "jupiter_token_address", // Swap token
"amount": "1000000", // Initial amount to swap (in Solana units)
"new_balance": "1500000" // New balance after swapping (in Solana units)
}
]
}
Here’s what changed:
- We added the
new_balance
field, which represents the new balance after the swap.
- The
amount
field is now updated to include the initial amount of SOL being swapped.
Example Use Case
To test this solution, you can use a tool like QuickNode ( or a programming language’s API to create a transaction string with the above code. When you sign the transaction using your wallet, you should see an updated balance displayed in the wallet.
Conclusion
The Jupiter swap API provides a convenient way to swap tokens on the Solana blockchain. However, when displaying balance changes after swapping, users may not be aware of their current balances before and after the swap. By updating the balance
field with the new balance after swapping, users can accurately track their token balances and make informed decisions about their investments.
By implementing this solution, wallet providers can improve user experience by providing more accurate information about balance changes, which is essential for managing Solana accounts effectively.