swap
curl --request POST \
--url https://api.jup.ag/swap/v1/swap \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"userPublicKey": "BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV",
"quoteResponse": {
"inputMint": "So11111111111111111111111111111111111111112",
"inAmount": "100000000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outAmount": "17057460",
"otherAmountThreshold": "16886885",
"swapMode": "ExactIn",
"slippageBps": 100,
"priceImpactPct": "0.0001",
"routePlan": []
},
"dynamicComputeUnitLimit": true,
"dynamicSlippage": true,
"prioritizationFeeLamports": {
"priorityLevelWithMaxLamports": {
"priorityLevel": "veryHigh",
"maxLamports": 1000000
}
}
}
'import requests
url = "https://api.jup.ag/swap/v1/swap"
payload = {
"userPublicKey": "BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV",
"quoteResponse": {
"inputMint": "So11111111111111111111111111111111111111112",
"inAmount": "100000000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outAmount": "17057460",
"otherAmountThreshold": "16886885",
"swapMode": "ExactIn",
"slippageBps": 100,
"priceImpactPct": "0.0001",
"routePlan": []
},
"dynamicComputeUnitLimit": True,
"dynamicSlippage": True,
"prioritizationFeeLamports": { "priorityLevelWithMaxLamports": {
"priorityLevel": "veryHigh",
"maxLamports": 1000000
} }
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
userPublicKey: 'BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV',
quoteResponse: {
inputMint: 'So11111111111111111111111111111111111111112',
inAmount: '100000000',
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
outAmount: '17057460',
otherAmountThreshold: '16886885',
swapMode: 'ExactIn',
slippageBps: 100,
priceImpactPct: '0.0001',
routePlan: []
},
dynamicComputeUnitLimit: true,
dynamicSlippage: true,
prioritizationFeeLamports: {
priorityLevelWithMaxLamports: {priorityLevel: 'veryHigh', maxLamports: 1000000}
}
})
};
fetch('https://api.jup.ag/swap/v1/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.jup.ag/swap/v1/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userPublicKey' => 'BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV',
'quoteResponse' => [
'inputMint' => 'So11111111111111111111111111111111111111112',
'inAmount' => '100000000',
'outputMint' => 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
'outAmount' => '17057460',
'otherAmountThreshold' => '16886885',
'swapMode' => 'ExactIn',
'slippageBps' => 100,
'priceImpactPct' => '0.0001',
'routePlan' => [
]
],
'dynamicComputeUnitLimit' => true,
'dynamicSlippage' => true,
'prioritizationFeeLamports' => [
'priorityLevelWithMaxLamports' => [
'priorityLevel' => 'veryHigh',
'maxLamports' => 1000000
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.jup.ag/swap/v1/swap"
payload := strings.NewReader("{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.jup.ag/swap/v1/swap")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.jup.ag/swap/v1/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"swapTransaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAEN...",
"lastValidBlockHeight": 324307300,
"prioritizationFeeLamports": 254600,
"dynamicSlippageReport": {
"slippageBps": 12,
"otherAmount": 17055413,
"simulatedIncurredSlippageBps": 1,
"amplificationRatio": "1.5"
}
}Swap
Request for a base64-encoded unsigned swap transaction based on the /quote response
POST
/
swap
swap
curl --request POST \
--url https://api.jup.ag/swap/v1/swap \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"userPublicKey": "BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV",
"quoteResponse": {
"inputMint": "So11111111111111111111111111111111111111112",
"inAmount": "100000000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outAmount": "17057460",
"otherAmountThreshold": "16886885",
"swapMode": "ExactIn",
"slippageBps": 100,
"priceImpactPct": "0.0001",
"routePlan": []
},
"dynamicComputeUnitLimit": true,
"dynamicSlippage": true,
"prioritizationFeeLamports": {
"priorityLevelWithMaxLamports": {
"priorityLevel": "veryHigh",
"maxLamports": 1000000
}
}
}
'import requests
url = "https://api.jup.ag/swap/v1/swap"
payload = {
"userPublicKey": "BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV",
"quoteResponse": {
"inputMint": "So11111111111111111111111111111111111111112",
"inAmount": "100000000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outAmount": "17057460",
"otherAmountThreshold": "16886885",
"swapMode": "ExactIn",
"slippageBps": 100,
"priceImpactPct": "0.0001",
"routePlan": []
},
"dynamicComputeUnitLimit": True,
"dynamicSlippage": True,
"prioritizationFeeLamports": { "priorityLevelWithMaxLamports": {
"priorityLevel": "veryHigh",
"maxLamports": 1000000
} }
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
userPublicKey: 'BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV',
quoteResponse: {
inputMint: 'So11111111111111111111111111111111111111112',
inAmount: '100000000',
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
outAmount: '17057460',
otherAmountThreshold: '16886885',
swapMode: 'ExactIn',
slippageBps: 100,
priceImpactPct: '0.0001',
routePlan: []
},
dynamicComputeUnitLimit: true,
dynamicSlippage: true,
prioritizationFeeLamports: {
priorityLevelWithMaxLamports: {priorityLevel: 'veryHigh', maxLamports: 1000000}
}
})
};
fetch('https://api.jup.ag/swap/v1/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.jup.ag/swap/v1/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userPublicKey' => 'BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV',
'quoteResponse' => [
'inputMint' => 'So11111111111111111111111111111111111111112',
'inAmount' => '100000000',
'outputMint' => 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
'outAmount' => '17057460',
'otherAmountThreshold' => '16886885',
'swapMode' => 'ExactIn',
'slippageBps' => 100,
'priceImpactPct' => '0.0001',
'routePlan' => [
]
],
'dynamicComputeUnitLimit' => true,
'dynamicSlippage' => true,
'prioritizationFeeLamports' => [
'priorityLevelWithMaxLamports' => [
'priorityLevel' => 'veryHigh',
'maxLamports' => 1000000
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.jup.ag/swap/v1/swap"
payload := strings.NewReader("{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.jup.ag/swap/v1/swap")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.jup.ag/swap/v1/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userPublicKey\": \"BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV\",\n \"quoteResponse\": {\n \"inputMint\": \"So11111111111111111111111111111111111111112\",\n \"inAmount\": \"100000000\",\n \"outputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outAmount\": \"17057460\",\n \"otherAmountThreshold\": \"16886885\",\n \"swapMode\": \"ExactIn\",\n \"slippageBps\": 100,\n \"priceImpactPct\": \"0.0001\",\n \"routePlan\": []\n },\n \"dynamicComputeUnitLimit\": true,\n \"dynamicSlippage\": true,\n \"prioritizationFeeLamports\": {\n \"priorityLevelWithMaxLamports\": {\n \"priorityLevel\": \"veryHigh\",\n \"maxLamports\": 1000000\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"swapTransaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAEN...",
"lastValidBlockHeight": 324307300,
"prioritizationFeeLamports": 254600,
"dynamicSlippageReport": {
"slippageBps": 12,
"otherAmount": 17055413,
"simulatedIncurredSlippageBps": 1,
"amplificationRatio": "1.5"
}
}Metis Swap API is no longer actively maintained and has been superseded by Swap V2.
Authorizations
Get API key via https://developers.jup.ag/portal
Body
application/json
Show child attributes
Show child attributes
- Allow a custom payer to pay for the transaction fees and rent of token accounts
- Note that users can close their ATAs elsewhere and have you reopen them again, your fees should account for this
- To automatically wrap/unwrap SOL in the transaction, as WSOL is an SPL token while native SOL is not
- When true and input mint is SOL, it will wrap the SOL amount to WSOL and swap
- When true and output mint is SOL, it will unwrap the WSOL back to SOL
- When true, the wSOL token account is always closed after the transaction, regardless of whether SOL is the input or output mint
- When false and input mint is SOL, it will use existing WSOL amount to swap
- When false and output mint is SOL, it will not unwrap the WSOL to SOL
- To set this parameter to false, you need to have the WSOL token account initialized
- 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)
- An initialized 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
- Swap API no longer requires the use of the Referral Program
- If
platformFeeBpsis passed in/quote, thefeeAccountmust be passed as well
- 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
- 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-instructionsto add both at the same time - Defaults to
auto, but preferred to usepriorityLevelWithMaxLamportsas it may be more accurate when accounting local fee market - Fixed lamports can be passed in as an integer in the
prioritizationFeeLamportsparameter
- priorityLevelWithMaxLamports
- jitoTipLamports
- jitoTipLamportsWithPayer
Show child attributes
Show child attributes
- Builds a legacy transaction rather than the default versioned transaction
- Used together with
asLegacyTransactionin/quote, otherwise the transaction might be too large
- 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
destinationTokenAccountandnativeDestinationAccountare mutually exclusive
- Public key of an account that will be used to receive the native SOL token out of the swap
- If not provided, the swap will default unwrap the WSOL and transfer the native SOL to the swap authority account
- If provided, we will unwrap the WSOL and transfer the native SOL to the account
- Only works if the output mint is SOL, is using the V2 instructions and the account passed in is not owned by token program
- When sending native SOL to a new account, you must swap at least enough to cover the rent required to create it.
destinationTokenAccountandnativeDestinationAccountare mutually exclusive
- When enabled, simulates the swap to provide an accurate compute unit limit in the transaction
- This incurs one extra RPC call to simulate
- Recommended for all normal flows — reduces priority fees needed and improves transaction landing
- When enabled, it will not do any additional RPC calls to check on required accounts
- The returned swap transaction will still attempt to create required accounts regardless if it exists or not
- When enabled, it estimates slippage and apply it in the swap transaction directly, overwriting the
slippageBpsparameter in the quote response. - This is no longer maintained, we are focusing efforts on RTSE on Ultra Swap API
- To use an exact compute unit price to calculate priority fee
computeUnitLimit (1400000) * computeUnitPriceMicroLamports- We recommend using
prioritizationFeeLamportsanddynamicComputeUnitLimitinstead of passing in your own compute unit price
- 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
Was this page helpful?
⌘I
