Quickstart
Get your first swap quote with Titan.
This is a minimal example to get your first quote from the Titan API. For a complete integration with transaction building, signing, and error handling, see Stream & Execute a Swap.
Titan has two integration paths. Titan Direct uses WebSocket and streams live quotes continuously. Titan Gateway uses REST and returns a single set of quotes per request. Both deliver the same quote quality.
The @titanexchange/sdk-ts SDK supports Titan Direct (WebSocket) only.
Connect and get a quote
import { V1Client } from '@titanexchange/sdk-ts';
import bs58 from 'bs58';
const client = await V1Client.connect(
`${process.env.TITAN_ENDPOINT}?auth=${process.env.TITAN_API_KEY}`
);
const { stream } = await client.newSwapQuoteStream({
swap: {
inputMint: bs58.decode('So11111111111111111111111111111111111111112'),
outputMint: bs58.decode('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
amount: BigInt(1_000_000_000), // 1 SOL in lamports
slippageBps: 50,
},
transaction: {
userPublicKey: bs58.decode('YOUR_WALLET_PUBLIC_KEY'),
},
});
for await (const update of stream) {
const quotes = update.quotes;
if (!Object.keys(quotes).length) continue;
for (const [provider, route] of Object.entries(quotes as Record<string, any>)) {
console.log(`${provider}: ${route.outAmount} out`);
}
break; // First update received — stop here
}
await client.close();Request a quote
import { decode } from '@msgpack/msgpack';
const params = new URLSearchParams({
inputMint: 'So11111111111111111111111111111111111111112',
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
amount: '1000000000', // 1 SOL in lamports
userPublicKey: 'YOUR_WALLET_PUBLIC_KEY',
slippageBps: '50',
});
const res = await fetch(
`${process.env.TITAN_ENDPOINT}/api/v1/quote/swap?${params}`,
{
headers: {
'Authorization': `Bearer ${process.env.TITAN_API_KEY}`,
'Accept': 'application/vnd.msgpack',
},
}
);
if (!res.ok) throw new Error(`${res.status}: ${res.statusText}`);
const data = decode(new Uint8Array(await res.arrayBuffer())) as any;
for (const [provider, route] of Object.entries(data.quotes as Record<string, any>)) {
console.log(`${provider}: ${route.outAmount} out`);
}What a quote looks like
The response contains a quotes map keyed by provider ID — "Titan", "Metis", "Okx", etc. Each entry is a SwapRoute with everything you need to build and send a transaction:
inAmount/outAmount— the input and output amounts for this route.slippageBps— the slippage tolerance applied to this quote.computeUnitsSafe— recommended compute budget that accounts for on-chain variance.instructions— the swap instructions to include in your transaction.addressLookupTables— ALT addresses needed to compile a V0 transaction.Quote expiry — if a route expires,
expiresAtMscontains the expiry as a millisecond UNIX timestamp andexpiresAfterSlotcontains the last valid slot. Check these before executing if present.
Not every provider appears in every response. Iterate with Object.entries(quotes) and pick the route with the best outAmount.
Next steps
Stream & Execute a Swap — full guide with transaction building, signing, and error handling
Configure Routing — filter venues and providers, set account limits
Authentication — JWT claims reference
Last updated

