Swap API

Solana Swap API

Build swap transactions server-side, sign with any wallet, then broadcast. Great for apps that want reliable swap construction without maintaining custom routing code.

Flow

  1. Call POST /swap/build to get an unsigned tx (base64).
  2. Sign the transaction client-side with your wallet.
  3. Call POST /swap/broadcast with the signed tx to execute.

Optional: attach a fee wallet/percent to monetize swaps in your own app.

Quick example

Curl | swap_build.sh
curl -X POST \
  -H "x-api-key: YOUR_KEY" \
  -H "content-type: application/json" \
  -d '{"userPublicKey":"...","inputMint":"So111...","outputMint":"EPjF...","amount":1000000,"slippageBps":50,"swapType":"buy"}' \
  https://us-east.dritan.dev/swap/build
TypeScript (SDK) | swap_build_and_broadcast.ts
import { DritanClient } from "dritan-sdk";
import { VersionedTransaction } from "@solana/web3.js";

const client = new DritanClient({ apiKey: process.env.DRITAN_API_KEY! });

const build = await client.buildSwap({
  userPublicKey: wallet.publicKey.toBase58(),
  inputMint: "So11111111111111111111111111111111111111112",
  outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  amount: 100_000_000,
  slippageBps: 50,
  swapType: "buy",
});

const tx = VersionedTransaction.deserialize(Buffer.from(build.transactionBase64, "base64"));
const signed = await wallet.signTransaction(tx);

const sent = await client.broadcastSwap(Buffer.from(signed.serialize()).toString("base64"));
console.log(sent.signature);

After signing, broadcast with /swap/broadcast.