TypeScript SDK
A typed client for the API, with safe retries and live order events.
Install
The package is not on npm yet, so there is no install command to run. Until it is published, call the HTTP API directly: every method below maps to one endpoint.
The install command appears here once the package is on npm. Until then, the API reference has every call in cURL, and quotes, orders and the full swap in JavaScript, Python and Go.
Quickstart
Quote a swap, create the order, and show the user where to send funds.
import { MindSwap } from '@mindswap/sdk'
const ms = new MindSwap({
apiKey: process.env.MINDSWAP_API_KEY!,
})
const quote = await ms.quote({
from: 'btc:bitcoin',
to: 'usdt:tron',
amountIn: '0.01',
})
if (!quote.mind.float) {
throw new Error('No MIND route right now')
}
const order = await ms.createOrder({
routeId: quote.mind.float,
pickedBy: 'mind',
payout: {
address: process.env.PAYOUT_ADDRESS!,
},
refund: {
address: process.env.REFUND_ADDRESS!,
},
})
const { amount, address } = order.deposit
console.log(`Send ${amount} BTC to ${address}`)Client options
Pass them to new MindSwap(options). All are optional.
Methods
Each method calls one endpoint and returns its typed answer.
assets()GET /v1/assetsquote(req)GET /v1/quotesquoteStream(req)GET /v1/quotes/streamcreateOrder(input, opts?)POST /v1/ordersgetOrder(id, { cap? })GET /v1/orders/{id}trackOrder(id, payoutAddress)POST /v1/orders/trackorderEvents(id, opts?)GET /v1/orders/{id}/eventsreportIssue(id, issue, { cap? })POST /v1/orders/{id}/issuesTypes
Generated from the API's OpenAPI file, so they always match what the API sends. Amounts are decimal strings in whole units, never numbers.
- AssetCatalog
- QuoteRequest
- QuoteSnapshot
- Route
- UnavailableRoute
- CreateOrderInput
- OrderView
- OrderStatus
- Deposit
- TrackResult
- OrderEvent
- ReportIssueBody
- IssueView
- ApiErrorCode
Errors
Every failure throws a MindSwapError. Branch on code; four codes have their own class. Messages never contain your key.
End user
Some routes are refused unless the create carries the end user's language and time zone. The SDK sends both from its runtime's Intl. A server that creates orders for many users passes each user's own. Never send a made-up value.
const order = await ms.createOrder(input, {
endUser: { language: 'de-DE', timeZone: 'Europe/Berlin' },
})Recovering a create
createOrder retries a lost answer with the same Idempotency-Key, so it never makes a second order. If retries run out or your process crashes, only that key finds the order again. For money flows, store the key with the user's intent before you call.
const key = crypto.randomUUID()
await db.saveIntent({ intentId, idempotencyKey: key, routeId, payout }) // persist first
const order = await ms.createOrder(input, { idempotencyKey: key })
// After a crash: call createOrder again with the same input and the stored key.
// The API answers with the original order and never creates a second one.Use from an agent
Not public yetOur MCP server wraps this SDK as six tools an agent can call. Every amount names its asset, order answers say what to do next, and create_order takes an intentId so a retry never makes a second order. It is not public yet, so there is no server to connect to today.
- list_assets
- get_quote
- create_order
- get_order
- track_order
- report_issue