Swap Websocket RPC Method
Please note that this method is only available for paid subscribers of Metis - Jupiter V6 Swap API.
To establish a WebSocket connection, you need to simply append '/ws' to your endpoint URL. For parameters, you can include them as URL arguments referred to as "params".
Parameters
jsonrpc
string
REQUIRED
The version of the JSON-RPC protocol being used
method
string
REQUIRED
The name of the method to be called. Here, it is 'swap'
id
integer
REQUIRED
A unique identifier for the request
params
object
REQUIRED
The parameters for the swap method
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
jsonrpc
string
The version of the JSON-RPC protocol being used
id
integer
A unique identifier for the request
result
object
The result of the swap
swapTransaction
string
The serialized transaction for the swap
lastValidBlockHeight
integer
The last valid block height
prioritizationFeeLamports
integer
The prioritization fee in lamports
Request
1wscat -c ws \2# wait for connection3{"jsonrpc": "2.0", "method": "swap", "params": {"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM", "quoteResponse": {"contextSlot":268877864,"inAmount":"1000000","inputMint":"So11111111111111111111111111111111111111112","otherAmountThreshold":"171916","outAmount":"171933","outputMint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","platformFee":null,"priceImpactPct":"0","routePlan":[{"percent":100,"swapInfo":{"ammKey":"9eBMcrerxoboDRLS5s8ntFzEnwC5fyfijmuimiM7Rzz","feeAmount":"100","feeMint":"So11111111111111111111111111111111111111112","inAmount":"1000000","inputMint":"So11111111111111111111111111111111111111112","label":"Meteora DLMM","outAmount":"151103","outputMint":"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"}},{"percent":100,"swapInfo":{"ammKey":"4dxE8odEd1663JR6LoqVvzoebAzGkYy6sQWS6nVARkej","feeAmount":"377","feeMint":"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN","inAmount":"151103","inputMint":"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN","label":"Meteora","outAmount":"3073721","outputMint":"KMNo3nJsBXfcpJTVhZcXLW7RmTwTt4GVFE7suUBo9sS"}},{"percent":100,"swapInfo":{"ammKey":"BhMCRAcCAZsAmirneeu3JcPXuQhuVMRW6UBmEPBmNq7N","feeAmount":"2265","feeMint":"KMNo3nJsBXfcpJTVhZcXLW7RmTwTt4GVFE7suUBo9sS","inAmount":"3073721","inputMint":"KMNo3nJsBXfcpJTVhZcXLW7RmTwTt4GVFE7suUBo9sS","label":"Meteora DLMM","outAmount":"171933","outputMint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}],"slippageBps":1,"swapMode":"ExactIn","timeTaken":0.008809088}}, "id": 1}
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free