NOTE
- Lite URL:
https://lite-api.jup.ag/swap/v1/swap - Pro URL:
https://api.jup.ag/swap/v1/swap
Let’s Get Started
In this guide, we will pick up from where Get Quote guide has left off. If you have not set up your environment to use the necessary libraries, the RPC connection to the network and successfully get a quote from the Quote API, please start at Environment Setup or get quote.Legacy Swap API
From the previous guide on getting a quote, now using the quote response and your wallet, you can receive a serialized swap transaction that needs to be prepared and signed before sending to the network.Get Serialized Transaction
Using the root URL and parameters to pass in, it is as simple as the example code below!What’s Next
Now, you are able to get a quote and use our Legacy Swap API to build the swap transaction for you. Next steps is to proceed to prepare and sign the transaction and send the signed transaction to the network.Additional Resources
Build Your Own Transaction With Instructions
If you prefer to compose with instructions instead of the provided transaction that is returned from the/swap endpoint (like the above example). You can post to /swap-instructions instead, it takes the same parameters as the /swap endpoint but returns you the instructions rather than the serialized transaction.
NOTEIn some cases, you may add more accounts to the transaction, which may exceed the transaction size limits. To work around this, you can use the
maxAccounts parameter in /quote endpoint to limit the number of accounts in the transaction.Refer to the GET /quote’s maxAccounts guide for more details./swap-instructions code snippet
/swap-instructions code snippet
Example code snippet of using
/swap-instructionBuild Your Own Transaction With Flash Fill Or CPI
If you prefer to interact with the Jupiter Swap Aggregator program with your own on-chain program. There are 2 ways to do it, typically on-chain program call Cross Program Invocation (CPI) to interact with each other, we also have another method called Flash Fill built by Jupiter (due to limitations of CPI in the past).CPI IS NOW RECOMMENDED!As of January 2025, Jupiter Swap via CPI is recommended for most users.The
Loosen CPI restriction feature has been deployed on Solana, you can read more here.CPI References
CPI References
A CPI transaction will be composed of these instructions:
- Borrow enough SOL from the program to open a wSOL account that the program owns.
- Swap X token from the user to wSOL on Jupiter via CPI.
- Close the wSOL account and send it to the program.
- The program then transfers the SOL back to the user.
To ease integration via CPI, you may add the following crate jupiter-cpi to your program.
To ease integration via CPI, you may add the following crate jupiter-cpi to your program.
jupiter-cpiTo ease integration via CPI, you may add the following crate to your program.In cargo.tomlIn your code
Flash Fill References
Flash Fill References
A Flash Fill transaction will be composed of these instructions:
- Borrow enough SOL for opening the wSOL account from this program.
- Create the wSOL account for the borrower.
- Swap X token to wSOL.
- Close the wSOL account and send it to the borrower.
- Repay the SOL for opening the wSOL account back to this program.
