Skip to content

Products

Swap Rate: fetch before you swap

Public endpoint, no API key required. Use this to show users a live quote before they confirm. Rates are valid for ~30 seconds.

Recommended flow: fetch rate → show expectedOutput and minOutput → call POST /api/v1/swap within the expiresAt window.
lowLiquidity: when true, the pool may not fill the full amount. Warn the user and consider reducing the swap size. liquidityUnknown: the balance behind that flag could not be read within the time budget of the quote. The price is unaffected, so treat it as not verified rather than insufficient.
Rate expiry: re-fetch if the user takes >30 s to confirm. Stale rates raise the chance of SLIPPAGE_EXCEEDED.
Rate limit: public, so throttled per source address: 60 requests/min by default, then 429 with a Retry-After header. Cache a quote for its 30-second validity rather than re-fetching per keystroke.
GET /api/v1/swap/rate (no auth required)
// Same-chain: USDT → nTZS on Base
const res = await fetch(
  'https://www.ntzs.co.tz/api/v1/swap/rate?from=USDT&to=NTZS&amount=100'
)
const rate = await res.json()
// {
//   from: "USDT",  to: "NTZS",  amount: 100,
//   fromChain: "base", toChain: "base",
//   midRate: 2639.8663,       // pair mid-rate (Bank of Tanzania mean, synced 4×/day)
//   bidBps: 57, askBps: 38,   // the quoted LP's spread
//   spreadBps: 38,            // the side this swap pays
//   protocolFeeBps: 20,       // platform toll, charged on top of the spread
//   tzsBuyRate: 2629.8348,    // nTZS a user RECEIVES per 1 stablecoin (spread only)
//   tzsSellRate: 2654.9133,   // nTZS a user PAYS for 1 stablecoin   (spread only)
//   rate: 2624.5751,          // effective rate after spread AND fee
//   expectedOutput: 262457.51,// what the user will receive
//   minOutput: 259832.93,     // expectedOutput × (1 − 1%); pass it to POST /swap as the floor
//   expiresAt: "2026-09-03T10:00:30.000Z",
//   lowLiquidity: false,
//   liquidityUnknown: false   // true when the solver balance could not be read in time; price unaffected
// }

// Cross-chain: USDT on BNB → nTZS on Base
const crossRate = await fetch(
  'https://www.ntzs.co.tz/api/v1/swap/rate' +
  '?from=USDT&to=NTZS&fromChain=bnb&toChain=base&amount=50'
)