The Titan team highly advises everyone to use the Meta Aggregator first as it does simulations and comparisons with multiple routers all in 1.
Setup
Using @faremeter/rides
Advanced Setup
Set up your payment handler in just 3 lines:import { payer } from "@faremeter/rides";
import { decode as msgpackDecode } from "@msgpack/msgpack";
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
await payer.addLocalWallet(PAYER_KEYPAIR);
@faremeter/rides automatically detects your network, looks up USDC, and sets up payments using your existing wallet.
All examples below use payer.fetch().
Set up your payment handler with full control:import {
clusterApiUrl,
Connection,
Keypair,
PublicKey,
} from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { lookupKnownSPLToken } from "@faremeter/info/solana";
import {
createPaymentHandler,
} from "@faremeter/payment-solana/exact";
import { wrap as wrapFetch } from "@faremeter/fetch";
import { decode as msgpackDecode } from "@msgpack/msgpack";
// Load keypair from environment
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
const network = "mainnet-beta";
// Lookup USDC mint address automatically
const usdcInfo = lookupKnownSPLToken(network, "USDC");
if (!usdcInfo) throw new Error("Could not find USDC mint");
const keypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(PAYER_KEYPAIR)),
);
const connection = new Connection(clusterApiUrl(network));
const mint = new PublicKey(usdcInfo.address);
const wallet = await createLocalWallet(network, keypair);
const fetchWithPayer = wrapFetch(fetch, {
handlers: [createPaymentHandler(wallet, mint, connection)],
});
This approach gives you full control over wallet creation, network configuration, and payment handlers.
Required for browser apps and custom wallet integration.
Example: Get Exchange Info
Query exchange information from Titan:
Using @faremeter/rides
Advanced Setup
const url = "https://titan-exchange.api.corbits.dev/api/v1/info";
const response = await payer.fetch(url, {
method: "GET",
headers: {
Accept: "application/msgpack" // or "application/json"
}
});
if (!response.ok) {
const text = await response.text().catch(() => "");
throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}
// Handle MessagePack response
const buffer = await response.arrayBuffer();
const data = msgpackDecode(new Uint8Array(buffer));
console.log("Titan Exchange Info:", JSON.stringify(data, null, 2));
const url = "https://titan-exchange.api.corbits.dev/api/v1/info";
const response = await fetchWithPayer(url, {
method: "GET",
headers: {
Accept: "application/msgpack" // or "application/json"
}
});
if (!response.ok) {
const text = await response.text().catch(() => "");
throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}
// Handle MessagePack response
const buffer = await response.arrayBuffer();
const data = msgpackDecode(new Uint8Array(buffer));
console.log("Titan Exchange Info:", JSON.stringify(data, null, 2));
Handling MessagePack Response
Titan Exchange API uses MessagePack format. You must decode the response using a MessagePack library:
const response = await payer.fetch(url, {
method: "GET",
headers: {
Accept: "application/msgpack"
}
});
const buffer = await response.arrayBuffer();
const data = msgpackDecode(new Uint8Array(buffer));
console.log(data);
Example Response
{
"protocolVersion": {
"major": 1,
"minor": 0,
"patch": 2
},
"settings": {
"quoteUpdate": {
"intervalMs": {
"min": 400,
"max": 3600000,
"default": 800
},
"numQuotes": {
"min": 1,
"max": 10,
"default": 1
}
},
"swap": {
"slippageBps": {
"min": 0,
"max": 10000,
"default": 100
},
"onlyDirectRoutes": false,
"addSizeConstraint": true,
"sizeConstraint": 1168
},
"transaction": {
"closeInputTokenAccount": false,
"createOutputTokenAccount": true
},
"connection": {
"concurrentStreams": 5
}
}
}
Payment Flow
- Initial Request: Client sends GET request without Bearer token
- 402 Response: Proxy returns payment requirements
{
"accepts": [{
"network": "solana-mainnet-beta",
"maxAmountRequired": 10000,
"asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"payTo": "corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"
}]
}
- Payment:
payer.fetch() or fetchWithPayer transfers 0.01 USDC on Solana
- Request Forwarded: Proxy adds
Authorization: Bearer <token> and forwards
Installing MessagePack
To decode MessagePack responses, install the library:
npm install @msgpack/msgpack
import { decode as msgpackDecode } from "@msgpack/msgpack";
External Resources