Project type: DEX Aggregator 

How to Integrate Jupiter Swap [API Documentation]
Skip to main content**Jupiter Station**GuidesDocsAPI PlaygroundPartnersStats 
+ V6 Swap API
+ (Deprecated) Price API V1
+ Price API V2
+ CPI / Smart Contract Integration
+ Game Dev (C#)
+ Self-hosted V6 Swap API
* Projects and Dexes
* V6 Swap API
On this page# V6 Swap API
infoIf you have problems landing transactions, read Landing Transactions on Solana.
Jupiter APIs is the easiest way for developers to access liquidity on Solana. Simply pass in the desired pairs, amount, and slippage, and the API will return the serialized transactions needed to execute the swap, which can then be passed into the Solana blockchain with the required signatures.
Risk Disclaimer**Please use Jupiter's Swap API at your own risk**. Jupiter's Frontend UI contains multiple safeguards and warnings when quoting. Jupiter is not liable for losses incurred by users on other platforms.
## V6 API Reference​
All Jupiter swaps are using versioned transactions and address lookup tables. But not all wallets support Versioned Transactions yet, so if you detect a wallet that does not support versioned transactions, you will need to use the `asLegacyTransaction` parameter.
Learn more about the Jupiter API Documentation at the OpenAPI documentation. This documentation has a REST request list and a built in API Playground. Use the API Playground to try API calls now!
API Documentation OpenAPI Documentation
### Guide for V6 Swap API (code example)​
#### 1. Install required libraries​
Running this example requires a minimum of NodeJS 16 In your command line terminal, install the libraries.
#### 2. Import from libraries and setup connection​
Next you can copy the following code snippets to a javascript file jupiter-api-example.js. And when you are ready to run the code, just type: *node jupiter-api-example.js*
import { Connection, Keypair, VersionedTransaction } from '@solana/web3.js';
import fetch from 'cross-fetch';
import { Wallet } from '@project-serum/anchor';
import bs58 from 'bs58';
// It is recommended that you use your own RPC endpoint.
// This RPC endpoint is only for demonstration purposes so that this example will run.
const connection = new Connection('
tipAlways make sure that you are using your own RPC endpoint. The RPC endpoint used by the connection object in the above example may not work anymore. For more information about RPC endpoints see the official Solana Documentation to learn more about their public RPC endpoints.
#### 3. Setup your wallet​
You can paste in your private key for testing purposes but this is not recommended for production applications.
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY || '')));
#### 4. Get the route for a swap​
Here, we are getting a quote to swap from SOL to USDC.
// Swapping SOL to USDC with input 0.1 SOL and 0.5% slippage
const quoteResponse = await (
// console.log({ quoteResponse })
#### 5. Get the serialized transactions to perform the swap​
Once we have the quote, we need to serialize the quote into a swap transaction that can be submitted on chain.
// get serialized transactions for the swap
const { swapTransaction } = await (
// quoteResponse from /quote api
// user public key to be used for the swap
// auto wrap and unwrap SOL. default is true
// feeAccount is optional. Use if you want to charge a fee. feeBps must have been passed in /quote API.
#### 6. Deserialize and sign the transaction​
// deserialize the transaction
const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
var transaction = VersionedTransaction.deserialize(swapTransactionBuf);
// sign the transaction
#### 7. Execute the transaction​
// get the latest block hash
const latestBlockHash = await connection.getLatestBlockhash();
// Execute the transaction
const rawTransaction = transaction.serialize()
const txid = await connection.sendRawTransaction(rawTransaction, {
Solana Network CongestionDue to the network congestion on Solana, the `sendRawTransaction` method may not be able to help you to land your transaction. You should check out this `transactionSender` file to send transaction.
import { Connection, Keypair, VersionedTransaction } from '@solana/web3.js';
import fetch from 'cross-fetch';
import { Wallet } from '@project-serum/anchor';
import bs58 from 'bs58';
// It is recommended that you use your own RPC endpoint.
// This RPC endpoint is only for demonstration purposes so that this example will run.
const connection = new Connection('
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY || '')));
// Swapping SOL to USDC with input 0.1 SOL and 0.5% slippage
const quoteResponse = await (
// console.log({ quoteResponse })
// get serialized transactions for the swap
const { swapTransaction } = await (
// quoteResponse from /quote api
// user public key to be used for the swap
// auto wrap and unwrap SOL. default is true
// feeAccount is optional. Use if you want to charge a fee. feeBps must have been passed in /quote API.
// deserialize the transaction
const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
var transaction = VersionedTransaction.deserialize(swapTransactionBuf);
// sign the transaction
// Execute the transaction
const rawTransaction = transaction.serialize()
const txid = await connection.sendRawTransaction(rawTransaction, {
## Advanced error handling to disable certain AMM from the API​
Sometimes an AMM will throw an error when swapping. To prevent getting a quote from the failed AMM, you can use the `excludeDexes` parameter when getting `/quote`.
Example JS, with the help of `@mercurial-finance/optimist` package:
import { parseErrorForTransaction } from '@mercurial-finance/optimist';
// TX ID from last step if the transaction failed.
const transaction = connection.getTransaction(txid, {
const programIdToLabelHash = await (
const { programIds } = parseErrorForTransaction(transaction);
let excludeDexes = new Set();
for (let programId of programIds) {
let foundLabel = programIdToLabelHash[programId];
// Request another quote with `excludeDexes`.
const { data } = await (
## Instructions Instead of Transaction​
Sometimes you may prefer to compose using instructions instead of one transaction that is returned from the `/swap` endpoint. You can post to `/swap-instructions` instead, it takes the same parameters as the `/swap` endpoint.
const instructions = await (
// quoteResponse from /quote api
throw new Error("Failed to get swap instructions: " + instructions.error);
tokenLedgerInstruction, // If you are using `useTokenLedger = true`.
computeBudgetInstructions, // The necessary instructions to setup the compute budget.
setupInstructions, // Setup missing ATA for the users.
swapInstruction: swapInstructionPayload, // The actual swap instruction.
cleanupInstruction, // Unwrap the SOL if `wrapAndUnwrapSol = true`.
addressLookupTableAddresses, // The lookup table addresses that you can use if you are using versioned transaction.
const deserializeInstruction = (instruction) => {
keys: instruction.accounts.map((key) => ({
const getAddressLookupTableAccounts = async (
): Promise<AddressLookupTableAccount[]> => {
keys.map((key) => new PublicKey(key))
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
const addressLookupTableAddress = keys[index];
const addressLookupTableAccount = new AddressLookupTableAccount({
const addressLookupTableAccounts: AddressLookupTableAccount[] = [];
const blockhash = (await connection.getLatestBlockhash()).blockhash;
const messageV0 = new TransactionMessage({
// uncomment if needed: ...setupInstructions.map(deserializeInstruction),
// uncomment if needed: deserializeInstruction(cleanupInstruction),
const transaction = new VersionedTransaction(messageV0);
## Using `maxAccounts`​
Sometimes, if you are composing with Jupiter Swap instruction, you may want to spare some accounts (64 max in 1 Solana transaction)
for your own program instruction, you can use `maxAccounts`.
// If you know that your instruction will take up 10 accounts, you
// can pass in 54 as `maxAccounts` when quoting.
const { data } = await (
const quoteResponse = data;
The `maxAccounts` is an estimation since it doesn't consider account overlapping but it is a good start to control how many accounts
you want per transaction.
## Using Token Ledger Instruction​
Sometimes you may not know the exact input amount for the Jupiter swap until an instruction before the swap happens.
const instructions = await (
// quoteResponse from /quote api
tokenLedgerInstruction: tokenLedgerPayload, // If you are using `useTokenLedger = true`.
swapInstruction: swapInstructionPayload, // The actual swap instruction.
addressLookupTableAddresses, // The lookup table addresses that you can use if you are using versioned transaction.
// A withdraw instruction that will increase the user input token account amount.
const withdrawInstruction = ...;
// Coupled with the tokenLedgerInstruction, the swap instruction will use the
// user increased amount of the input token account after the withdrawal as input amount.
const tokenLedgerInstruction = new TransactionInstruction({
keys: tokenLedgerPayload.accounts.map((key) => ({
const swapInstruction = new TransactionInstruction({
keys: swapInstructionPayload.accounts.map((key) => ({
const getAdressLookupTableAccounts = async (
): Promise<AddressLookupTableAccount[]> => {
keys.map((key) => new PublicKey(key))
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
const addressLookupTableAddress = keys[index];
const addressLookupTableAccount = new AddressLookupTableAccount({
const addressLookupTableAccounts: AddressLookupTableAccount[] = [];
const messageV0 = new TransactionMessage({
instructions: [tokenLedgerInstruction, withdrawInstruction, swapInstruction],
const transaction = new VersionedTransaction(messageV0);
This can be useful if you want to withdraw from Solend and immediately convert your withdrawal token into another token with Jupiter.
## Setting Priority Fee for Your Transaction​
If transactions are expiring without confirmation on-chain, this might mean that you have to pay additional fees to prioritize your transaction. To do so, you can set the `computeUnitPriceMicroLamports` parameter.
const transaction = await (
// quoteResponse from /quote api
// user public key to be used for the swap
dynamicComputeUnitLimit: true, // allow dynamic compute limit instead of max 1,400,000
// custom priority fee
prioritizationFeeLamports: 'auto' // or custom lamports: 1000
If 'auto' is used, Jupiter will automatically set a priority fee for the transaction, it will be capped at 5,000,000 lamports / 0.005 SOL.
## Using Dynamic Slippage​
To understand what Dynamic Slippage is, checkout our Jupresearch post 
Dynamic slippage is a slippage estimation and optimization mechanism during the /swap call, and is useful because:
* Estimates slippage closer to the time of execution.
* A set of heuristics that accounts for the type of token traded and user's max slippage tolerance.
* Safeguards the user while ensuring success rate.
The frontend sends a payload to the backend with an additional `dynamicSlippage` field with `maxBps` set as the user's max slippage **(this is important to respect the user's max, the jup.ag UI sets the default to 300bps (3%))**.
// get serialized transactions for the swap
const { swapTransaction } = await (
// quoteResponse from /quote api
// user public key to be used for the swap
// auto wrap and unwrap SOL. default is true
// jup.ag frontend default max for user
dynamicSlippage: { "maxBps": 300 },
// feeAccount is optional. Use if you want to charge a fee. feeBps must have been passed in /quote API.
The backend returns a response with a serialized transaction that is already using the final optimized slippage and a `dynamicSlippageReport` for visibility/error catching.
"swapTransaction": "// serialized transaction",
// the final optimized slippage bps used in the serialized transaction
// the incurred out amount observed from simulating the transaction
// the simulated incurred slippage during optimization
// negative integer refers to the loss in bps while positive refers to the gain
// an amplifcation ratio we use to add a buffer to the estimated slippage
## Examples​
For more example scripts please visit the jupiter-quote-api-node public Git repository The repository has some further scripts and instructions for you to explore!
Having issues? Head to the Troubleshooting section for some help.
Edit this page APIs](/docs/api)NextPayments API* V6 API Reference
+ Guide for V6 Swap API (code example)
* Advanced error handling to disable certain AMM from the API
* Instructions Instead of Transaction
* Using Token Ledger Instruction
* Setting Priority Fee for Your Transaction
* Using Dynamic Slippage