Skip to main content

swap-instructions

POST 

https://lite-api.jup.ag/swap/v1/swap-instructions

Request for swap instructions that you can use from the quote you get from /quote

note

Refer to Swap API doc for more information

Request

Bodyrequired

    userPublicKeystringrequired
    wrapAndUnwrapSolboolean
    • To automatically wrap/unwrap SOL in the transaction, as WSOL is an SPL token while native SOL is not
    • When true, it will strictly use SOL amount to wrap it to swap, and each time after you swap, it will unwrap all WSOL back to SOL
    • When false, it will strictly use WSOL amount to swap, and each time after you swap, it will not unwrap the WSOL back to SOL
    • To set this parameter to false, you need to have the WSOL token account initialized
    • Parameter will be ignored if destinationTokenAccount is set because the destinationTokenAccount may belong to a different user that we have no authority to close
    Default value: true
    useSharedAccountsboolean
    • The default is determined dynamically by the routing engine, allowing us to optimize for compute units, etc
    • This enables the usage of shared program accounts, this is essential as complex routing will require multiple intermediate token accounts which the user might not have
    • If true, you do not need to handle the creation of intermediate token accounts for the user
    • Do note, shared accounts route will fail on some new AMMs (low liquidity token)
    feeAccountstring
    • An token account that will be used to collect fees
    • The mint of the token account can only be either the input or output mint of the swap
    • You no longer are required to use the Referral Program
    • See Add Fees guide for more details
    trackingAccountstring
    • Specify any public key that belongs to you to track the transactions
    • Useful for integrators to get all the swap transactions from this public key
    • Query the data using a block explorer like Solscan/SolanaFM or query like Dune/Flipside
    prioritizationFeeLamports object
    • To specify a level or amount of additional fees to prioritize the transaction
    • It can be used for EITHER priority fee OR Jito tip (not both at the same time)
    • If you want to include both, you will need to use /swap-instructions to add both at the same time
    priorityLevelWithMaxLamports object
    priorityLevelstring

    Possible values: [medium, high, veryHigh]

    maxLamportsinteger
    • Maximum lamports to cap the priority fee estimation, to prevent overpaying
    jitoTipLamportsinteger
    • Exact amount of tip to use in a tip instruction
    • Refer to Jito docs on how to estimate the tip amount based on percentiles
    • It has to be used together with a connection to a Jito RPC
    • See their docs
    asLegacyTransactionboolean
    • Builds a legacy transaction rather than the default versioned transaction
    • Used together with asLegacyTransaction in /quote, otherwise the transaction might be too large
    Default value: false
    destinationTokenAccountstring
    • Public key of a token account that will be used to receive the token out of the swap
    • If not provided, the signer's token account will be used
    • If provided, we assume that the token account is already initialized
    dynamicComputeUnitLimitboolean
    • When enabled, it will do a swap simulation to get the compute unit used and set it in ComputeBudget's compute unit limit
    • This incurs one extra RPC call to simulate this
    • We recommend to enable this to estimate compute unit correctly and reduce priority fees needed or have higher chance to be included in a block
    Default value: false
    skipUserAccountsRpcCallsboolean
    • When enabled, it will not do any additional RPC calls to check on required accounts
    • Enable it only when you already setup all the accounts needed for the trasaction, like wrapping or unwrapping sol, or destination account is already created
    Default value: false
    dynamicSlippageboolean
    • When enabled, it estimates slippage and apply it in the swap transaction directly, overwriting the slippageBps parameter in the quote response.
    • Used together with dynamicSlippage in /quote, otherwise the slippage used will be the one in the /quote's slippageBps
    • See notes for more information
    Default value: false
    computeUnitPriceMicroLamportsinteger
    • To use an exact compute unit price to calculate priority fee
    • computeUnitLimit (1400000) * computeUnitPriceMicroLamports
    • We recommend using prioritizationFeeLamports and dynamicComputeUnitLimit instead of passing in your own compute unit price
    blockhashSlotsToExpiryinteger
    • Pass in the number of slots we want the transaction to be valid for
    • Example: If you pass in 10 slots, the transaction will be valid for ~400ms * 10 = approximately 4 seconds before it expires
    quoteResponse objectrequired
    inputMintstringrequired
    inAmountstringrequired
    outputMintstringrequired
    outAmountstringrequired
    • Calculated output amount from routing engine
    • The value includes platform fees and DEX fees, excluding slippage
    otherAmountThresholdstringrequired
    • Calculated minimum output amount after accounting for slippageBps on the outAmount value
    • Not used by /swap endpoint to build transaction
    swapModeSwapMode (string)required

    Possible values: [ExactIn, ExactOut]

    slippageBpsint32required
    platformFee object
    amountstring
    feeBpsint32
    priceImpactPctstringrequired
    routePlan object[]required
  • Array [
  • swapInfo objectrequired
    ammKeystringrequired
    labelstring
    inputMintstringrequired
    outputMintstringrequired
    inAmountstringrequired
    outAmountstringrequired
    feeAmountstringrequired
    feeMintstringrequired
    percentint32required
  • ]
  • contextSlotnumber
    timeTakennumber

Responses

Successful response

Schema
    otherInstructions object[]
    • If you set {\"prioritizationFeeLamports\": {\"jitoTipLamports\": 5000}}, you will see a custom tip instruction to Jito here.
  • Array [
  • programIdstringrequired
    accounts object[]required
  • Array [
  • pubkeystringrequired
    isSignerbooleanrequired
    isWritablebooleanrequired
  • ]
  • datastringrequired
  • ]
  • computeBudgetInstructions object[]required
    • To setup the compute budget for the transaction.
  • Array [
  • programIdstringrequired
    accounts object[]required
  • Array [
  • pubkeystringrequired
    isSignerbooleanrequired
    isWritablebooleanrequired
  • ]
  • datastringrequired
  • ]
  • setupInstructions object[]required
    • To setup required token accounts for the users.
  • Array [
  • programIdstringrequired
    accounts object[]required
  • Array [
  • pubkeystringrequired
    isSignerbooleanrequired
    isWritablebooleanrequired
  • ]
  • datastringrequired
  • ]
  • swapInstruction objectrequired
    • The actual swap instruction.
    programIdstringrequired
    accounts object[]required
  • Array [
  • pubkeystringrequired
    isSignerbooleanrequired
    isWritablebooleanrequired
  • ]
  • datastringrequired
    cleanupInstruction object
    • To wrap and unwrap the SOL.
    programIdstringrequired
    accounts object[]required
  • Array [
  • pubkeystringrequired
    isSignerbooleanrequired
    isWritablebooleanrequired
  • ]
  • datastringrequired
    addressLookupTableAddressesstring[]required
    • The lookup table addresses if you are using versioned transaction.
curl -L 'https://lite-api.jup.ag/swap/v1/swap-instructions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"userPublicKey": "jdocuPgEAjMfihABsPgKEvYtsmMzjUHeq9LX4Hvs7f3",
"quoteResponse": {
"inputMint": "So11111111111111111111111111111111111111112",
"inAmount": "1000000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outAmount": "125630",
"otherAmountThreshold": "125002",
"swapMode": "ExactIn",
"slippageBps": 50,
"platformFee": null,
"priceImpactPct": "0",
"routePlan": [
{
"swapInfo": {
"ammKey": "AvBSC1KmFNceHpD6jyyXBV6gMXFxZ8BJJ3HVUN8kCurJ",
"label": "Obric V2",
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"inAmount": "1000000",
"outAmount": "125630",
"feeAmount": "5",
"feeMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
},
"percent": 100
}
]
},
"prioritizationFeeLamports": {
"priorityLevelWithMaxLamports": {
"maxLamports": 10000000,
"priorityLevel": "veryHigh"
}
},
"dynamicComputeUnitLimit": true
}'
Request Collapse all
Base URL
https://lite-api.jup.ag/swap/v1
Body required
{
  "userPublicKey": "jdocuPgEAjMfihABsPgKEvYtsmMzjUHeq9LX4Hvs7f3",
  "quoteResponse": {
    "inputMint": "So11111111111111111111111111111111111111112",
    "inAmount": "1000000",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "outAmount": "125630",
    "otherAmountThreshold": "125002",
    "swapMode": "ExactIn",
    "slippageBps": 50,
    "platformFee": null,
    "priceImpactPct": "0",
    "routePlan": [
      {
        "swapInfo": {
          "ammKey": "AvBSC1KmFNceHpD6jyyXBV6gMXFxZ8BJJ3HVUN8kCurJ",
          "label": "Obric V2",
          "inputMint": "So11111111111111111111111111111111111111112",
          "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
          "inAmount": "1000000",
          "outAmount": "125630",
          "feeAmount": "5",
          "feeMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
        },
        "percent": 100
      }
    ]
  },
  "prioritizationFeeLamports": {
    "priorityLevelWithMaxLamports": {
      "maxLamports": 10000000,
      "priorityLevel": "veryHigh"
    }
  },
  "dynamicComputeUnitLimit": true
}
ResponseClear

Click the Send API Request button above and see the response here!