Swaps (Jupiter)
You can route spot swaps using Jupiter. In TypeScript, the SDK exposes a JupiterClient plus a convenience driftClient.swap(...) helper.
import { Connection } from "@solana/web3.js";
import { JupiterClient } from "@drift-labs/sdk";
const connection = new Connection("<RPC_URL>", "confirmed");
const jupiterClient = new JupiterClient({ connection });Class JupiterClientReference ↗// Preview a quote before swapping (shape depends on Jupiter route selection).
const quote = await jupiterClient.getQuote({
inputMint: "<INPUT_MINT>",
outputMint: "<OUTPUT_MINT>",
amount: "<AMOUNT_IN_BASE_UNITS>",
});
console.log(quote);Method JupiterClient.getQuoteReference ↗// Assumes `driftClient` is subscribed.
const txSig = await driftClient.swap({
jupiterClient,
inMarketIndex: 0, // e.g. USDC
outMarketIndex: 1, // e.g. SOL
amount: driftClient.convertToSpotPrecision(0, 10), // 10 USDC (example)
slippageBps: 50,
onlyDirectRoutes: false,
});
console.log(txSig);Method DriftClient.swapReference ↗Last updated on