Skip to main content

/swap REST API Endpoint

Returns a transaction that you can use from the quote you get from /quote.

Updated on
May 31, 2024

/swap REST API Endpoint

Please note that this method is available for Free and Paid subscribers of Metis - Jupiter V6 Swap API, along with jupiterapi.com users.

Query Parameters

userPublicKey
string
REQUIRED
The user public key
wrapAndUnwrapSol
boolean
If set to true, it will automatically wrap/unwrap SOL. If it is false, it will use wSOL token account. It will be ignored if destinationTokenAccount is set because the destinationTokenAccount may belong to a different user that we have no authority to close. By default it is set to true
useSharedAccounts
boolean
This enables the usage of shared program accounts. That means no intermediate token accounts or open orders accounts need to be created for the users. But it also means that the likelihood of hot accounts is higher. By default, it is set to true
feeAccount
string
The fee token account is derived using the seeds ['referral_ata', referral_account, mint], along with the REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3 referral contract. Only pass in if you set a feeBps and make sure that the feeAccount has been created
computeUnitPriceMicroLamports
integer
The compute unit price to prioritize the transaction, the additional fee will be computeUnitLimit (1400000) * computeUnitPriceMicroLamports. If auto is used, Jupiter will automatically set a priority fee and it will be capped at 5,000,000 lamports / 0.005 SOL
prioritizationFeeLamports
integer
Prioritization fee lamports paid for the transaction in addition to the signatures fee. Mutually exclusive with compute_unit_price_micro_lamports. If auto is used, Jupiter will automatically set a priority fee and it will be capped at 5,000,000 lamports / 0.005 SOL
asLegacyTransaction
boolean
Request a legacy transaction rather than the default versioned transaction, needs to be paired with a quote using asLegacyTransaction otherwise the transaction might be too large. By default it is set as 'False'
useTokenLedger
boolean
This is useful when the instruction before the swap has a transfer that increases the input token amount. Then, the swap will just use the difference between the token ledger token amount and post token amount. By default, it is set to 'False'
destinationTokenAccount
string
Public key of the token account that will be used to receive the token out of the swap. If not provided, the user's ATA will be used. If provided, we assume that the token account is already initialized
dynamicComputeUnitLimit
boolean
When enabled, it will do a swap simulation to get the compute unit used and set it in ComputeBudget's compute unit limit. This will increase latency slightly since there will be one extra RPC call to simulate this. By default, it is set to false
skipUserAccountsRpcCalls
boolean
When enabled, it will not do any rpc calls check on user's accounts. Enable it only when you already setup all the accounts needed for the trasaction, like wrapping or unwrapping sol, destination account is already created.
quoteResponse
object
REQUIRED
The quoteResponse object which you can get from the response from the /quote method
inputMint
string
REQUIRED
The source token's mint address
inAmount
string
REQUIRED
The amount of the source token being swapped
outputMint
string
REQUIRED
The destination token's mint address
outAmount
string
REQUIRED
The amount of the destination token received after the swap
otherAmountThreshold
string
REQUIRED
A threshold amount for the destination token
swapMode
string
REQUIRED
Indicates the swap mode
slippageBps
integer
REQUIRED
Slippage tolerance in basis points
platformFee
object
The platform Fee object which contains the following fields:
amount
string
The amount of the platform fee
feeBps
integer
The fee percentage in basis points
priceImpactPct
string
REQUIRED
The percentage of price impact due to the swap
routePlan
array
REQUIRED
An array containing detailed information about each step of the swap process
swapInfo
object
REQUIRED
Detailed information about a specific swap step
ammKey
string
REQUIRED
The key identifying the Automated Market Maker (AMM) responsible for the swap
label
string
A label or identifier for the AMM
inputMint
string
REQUIRED
The mint address of the token being swapped from in this step
outputMint
string
REQUIRED
The mint address of the token being received in this step
inAmount
string
REQUIRED
The amount of the token being swapped from in this step
outAmount
string
REQUIRED
The amount of the token being received after the swap in this step
feeAmount
string
REQUIRED
The amount of fee charged for this step of the swap
feeMint
string
REQUIRED
The mint address of the token used for paying fees in this step
percent
integer
REQUIRED
The percentage allocation of the swap for this step
contextSlot
integer
A contextual identifier
timeTaken
integer
Time taken for the request to be processed

Returns

swapTransaction
string
The serialized transaction for the swap
lastValidBlockHeight
integer
The last valid block height
prioritizationFeeLamports
integer
The prioritization fee in lamports
Request
1
curl --location 'https://docs-demo.solana-mainnet.quiknode.pro/swap' \
2
--header 'Content-Type: application/json' \
3
--data '{
4
"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",
5
"quoteResponse": {
6
"inputMint": "So11111111111111111111111111111111111111112",
7
"inAmount": "1000000000",
8
"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",
9
"outAmount": "47737119",
10
"otherAmountThreshold": "47498434",
11
"swapMode": "ExactIn",
12
"slippageBps": 50,
13
"platformFee": null,
14
"priceImpactPct": "0",
15
"routePlan": [
16
{
17
"swapInfo": {
18
"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",
19
"label": "Phoenix",
20
"inputMint": "So11111111111111111111111111111111111111112",
21
"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",
22
"inAmount": "200000000",
23
"outAmount": "9546224",
24
"feeAmount": "4776",
25
"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"
26
},
27
"percent": 20
28
},
29
{
30
"swapInfo": {
31
"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",
32
"label": "Meteora DLMM",
33
"inputMint": "So11111111111111111111111111111111111111112",
34
"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",
35
"inAmount": "800000000",
36
"outAmount": "59167218",
37
"feeAmount": "240003",
38
"feeMint": "So11111111111111111111111111111111111111112"
39
},
40
"percent": 80
41
},
42
{
43
"swapInfo": {
44
"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",
45
"label": "Whirlpool",
46
"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",
47
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
48
"inAmount": "59167218",
49
"outAmount": "148627676",
50
"feeAmount": "0",
51
"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"
52
},
53
"percent": 100
54
},
55
{
56
"swapInfo": {
57
"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",
58
"label": "Phoenix",
59
"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
60
"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",
61
"inAmount": "148627676",
62
"outAmount": "38190895",
63
"feeAmount": "19105",
64
"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"
65
},
66
"percent": 100
67
}
68
],
69
"contextSlot": 257193413,
70
"timeTaken": 0.411891677
71
}
72
}'
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free