For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickstart

Get your first swap quote with Titan.

You'll need an API token and endpoint URL before starting. See Get API Access if you don't have one yet.

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.

Swap quote requests require a userPublicKey — a valid Solana wallet address. The server uses it to build transaction instructions scoped to that wallet.

The @titanexchange/sdk-ts SDK supports Titan Direct (WebSocket) only.

1

Install the SDK

npm install @titanexchange/sdk-ts bs58
2

Set your credentials

export TITAN_ENDPOINT="wss://YOUR_ENDPOINT/api/v1/ws"
export TITAN_API_KEY="YOUR_API_TOKEN"
3

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();
1

Install dependencies

npm install @msgpack/msgpack
2

Set your credentials

export TITAN_ENDPOINT="https://YOUR_ENDPOINT"
export TITAN_API_KEY="YOUR_API_TOKEN"
3

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, expiresAtMs contains the expiry as a millisecond UNIX timestamp and expiresAfterSlot contains 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

Last updated