Skip to main content

Execute Order

The root URL of the Ultra API's order endpoint is as such.

https://api.jup.ag/ultra/v1/execute
API Reference

To fully utilize the Ultra API, check out the Ultra API Reference.

Sign Transaction

Using the Solana web3.js v1 library, you can sign the transaction as follows:

// ... GET /order's response

// Extract the transaction from the order response
const transactionBase64 = orderResponse.transaction

// Deserialize the transaction
const transaction = VersionedTransaction.deserialize(Buffer.from(transactionBase64, 'base64'));

// Sign the transaction
transaction.sign([wallet.payer]);

// Serialize the transaction to base64 format
const signedTransaction = Buffer.from(transaction.serialize()).toString('base64');

Execute Order

By making a post request to the /execute endpoint, Jupiter executes the swap transaction on behalf of you/your users. This includes handling of slippage, priority fees, transaction landing and more.

To make a post request to execute a swap order, you need to pass in the required parameters:

  • signedTransaction: The signed transaction
  • requestId: The order response's request ID
/execute parameters

Both required parameters are found in the order response, do note that the transaction field is the base64 encoded transaction that you need to sign before submitting to the network.

const executeResponse = await (
await fetch('https://api.jup.ag/ultra/v1/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
signedTransaction: signedTransaction,
requestId: orderResponse.requestId,
}),
})
).json();

Execute Response

After making the post request to the /execute endpoint, you will receive a response with the status of the swap.

if (executeResponse.status === "Success") {
console.log('Swap successful:', JSON.stringify(executeResponse, null, 2));
console.log(`https://solscan.io/tx/${executeResponse.signature}`);
} else {
console.error('Swap failed:', JSON.stringify(executeResponse, null, 2));
console.log(`https://solscan.io/tx/${executeResponse.signature}`);
}

Example response of successful swap:

{
"status": "Success",
"signature": "transaction signature",
"slot": "323598314",
"code": 0,
"inputAmountResult": "9995000",
"outputAmountResult": "1274698",
"swapEvents": [
{
"inputMint": "So11111111111111111111111111111111111111112",
"inputAmount": "9995000",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outputAmount": "1274698"
}
]
}

Example response of failed swap:

{
"status": "Failed",
"signature": "transaction signature",
"error": "custom program error: #6023",
"code": 4615026,
"slot": "323597963"
}

Response Codes

The following is a list of error codes that can be returned by the /execute endpoint.

Ultra Endpoint Codes

CodeDescriptionDebugging
0Success-
-1Missing cached orderrequestId not found in cache, likely expired or not found
-2Invalid signed transactionsignedTransaction is invalid, likely failed to sign the transaction correctly
-3Invalid message bytessignedTransaction is invalid, likely due to incorrect usage of transaction field in the order response

Aggregator Swap Type Codes

CodeDescriptionDebugging
-1000Failed to landTransaction failed to land on the network
-1001Unknown error-
-1002Invalid transaction-
-1003Transaction not fully signed-
-1004Invalid block height-

RFQ Swap Type Codes

CodeDescriptionDebugging
-2000Failed to land-
-2001Unknown error-
-2002Invalid payload-
-2003Quote expiredUser did not respond in time or RFQ provider did not execute in time
-2004Swap rejectedUser or RFQ provider rejected the swap