API reference · v1

MindSwap API

The same API mindswap.io runs on. Amounts are decimal strings, never numbers.

Base URL
https://api.mindswap.io/v1
Key header
x-api-key: msk_live_…

Authentication

Send your key as x-api-key, or as Authorization: Bearer msk_live_…. Call from your server: the API only accepts browsers on mindswap.io.

Assets, quotes, tracking, problems
No key. Tracking and problem reports prove the order with its payout address.
Create an order
Optional. Without a key, open the order later with its ID and payout address.
Read an order or its events
The key that created it, or the cap from tracking (read-only, 24 h).

A new key works at once. Until your account's first completed order it gets the per-IP limits, then 1,200 calls a minute.

List assets

No key
GET/v1/assets

Every asset you can swap, with its networks and venues. Cached for 60 s: send If-None-Match with the ETag and an unchanged list answers 304.

curl https://api.mindswap.io/v1/assets
{
  "assets": [{
    "id": "btc:bitcoin",
    "symbol": "BTC",
    "name": "Bitcoin",
    "network": "bitcoin",
    "contract": null,
    "decimals": 8,
    "memo": "none",
    "status": "active"
  }, …],
  "networks": [ … ],
  "venues": [ … ]
}

Response

assets
Asset[]Each asset's id (symbol:network), symbol, name, network, decimals, memo rule and status.
networks
Network[]Each network's name, confirmations and explorer link.
venues
Venue[]The id, name and logo of each venue a route can run on.

Get quotes

No key
GET/v1/quotes

Every route we can run for this amount, answered by a deadline, grouped by order type with MIND's pick first. Routes that arrive late come through the stream.

Query

fromRequired
asset IDThe asset you send, symbol:network in lower case, for example btc:bitcoin.
toRequired
asset IDThe asset you receive, for example eth:ethereum.
amountInRequired
decimalHow much you send, in whole units as a string: "0.1" BTC, never satoshi.
curl https://api.mindswap.io/v1/quotes \
    --get \
    -d from=btc:bitcoin \
    -d to=eth:ethereum \
    -d amountIn=0.1
{
  "routes": [{
    "routeId": "r1.k1.Zk3v…",
    "kind": "exchange",
    "rateType": "fixed",
    "amountIn": "0.1",
    "amountOut": "3.5324",
    "fees": { "totalUser": {
      "amount": "0.0283",
      "asset": "eth:ethereum"
    } },
    "expiresAt": "2026-11-17T14:15:00Z"
  }],
  "mind": {
    "float": "r1.k1.Hn8w…",
    "fixed": "r1.k1.Zk3v…",
    "private": null
  },
  "complete": true
}

Response

routes
Route[]Each priced route. Pass its routeId to create an order before expiresAt.
mind
objectThe routeId MIND picks for float, fixed and private, or null.
complete
booleanFalse while late routes are still coming. Use the stream to get them.

Stream quotes

No key
GET/v1/quotes/stream

The same query as Get quotes, as server-sent events. A snapshot event carries the whole answer again each time a late route lands, then done carries the final one. Replace what you show with each event; never merge.

curl -N https://api.mindswap.io/v1/quotes/stream \
    --get \
    -d from=btc:bitcoin \
    -d to=eth:ethereum \
    -d amountIn=0.1
event: snapshot
data: { "routes": [ … ], "mind": { … }, "complete": false }

event: done
data: { "routes": [ … ], "mind": { … }, "complete": true }

Create an order

Key optional
POST/v1/orders

Turns a quoted route into an order and returns where the user sends the deposit. Never retried blindly: one Idempotency-Key per swap the user confirms.

Headers

Idempotency-KeyRequired
string8 to 64 printable characters, for example a UUID. A retry with the same key and body returns the first answer, never a second order.
Accept-LanguageOptional
stringThe end user's language, for example en-US. MIND float and private routes, and some exchange routes, refuse an order without it.
X-Client-TimezoneOptional
stringThe end user's IANA time zone, for example Europe/Berlin. Never a made-up value.

Body

routeIdRequired
stringFrom a quote, unchanged. It stops working at the route's expiresAt.
pickedByRequired
enummind when you take MIND's pick, otherwise user.
payoutRequired
address{ address, memo }. Set memo when the asset needs one, else null.
refundRequired
address | nullWhere a refund goes. Required for fixed routes; send it for every order.
refRequired
string | nullAn affiliate code, up to 20 characters. Send null when you have none.
curl https://api.mindswap.io/v1/orders \
    -H "x-api-key: $MINDSWAP_API_KEY" \
    -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
    -H "Accept-Language: en-US" \
    -H "X-Client-Timezone: Europe/Berlin" \
    -H "content-type: application/json" \
    -d @- <<JSON
{
  "routeId": "$ROUTE_ID",
  "pickedBy": "mind",
  "payout": { "address": "$PAYOUT_ADDRESS", "memo": null },
  "refund": { "address": "$REFUND_ADDRESS", "memo": null },
  "ref": null
}
JSON
{
  "id": "MS-7HK2PQ",
  "type": "fixed",
  "status": "awaiting_deposit",
  "deposit": {
    "address": "bc1q9h7garjv5p2m8u0kq4ksd2d6e0q3t5xw8yz2hf4n",
    "memo": null,
    "amount": "0.1",
    "expiresAt": "2026-11-17T14:30:00Z",
    "expiresSource": "provider"
  }
}

Read an order

Key or cap
GET/v1/orders/{id}

The order as the user sees it: status, deposit instructions, every step so far and the transactions.

Query

capOptional
stringFrom Track an order: read-only access for 24 h. Not needed with the key that created the order.
curl https://api.mindswap.io/v1/orders/$ORDER_ID \
    -H "x-api-key: $MINDSWAP_API_KEY"
{
  "id": "MS-7HK2PQ",
  "version": 0,
  "type": "fixed",
  "status": "awaiting_deposit",
  "deposit": { "address": "bc1q9h7g…", "amount": "0.1", … },
  "amountOut": "3.5324",
  "steps": [{ "status": "awaiting_deposit", "at": "2026-11-17T14:00:00Z" }],
  …
}

Response

status
enumawaiting_deposit, confirming, exchanging, private_routing, sending, completed, expired, refund_pending, refunded, failed, on_hold or partially_completed.
deposit
DepositWhere and how much to send, and until when: address, memo, amount, expiresAt.
steps
Step[]Every status the order entered, oldest first.
version
integerGoes up by one on every change. Drop any view that is not newer than the one you show.

Order events

Key or cap
GET/v1/orders/{id}/events

Server-sent events. The first event is the current order and each change sends the whole order again; a heartbeat comes every 15 s, and end closes the stream once the order can no longer change.

Query and headers

capOptional
stringFrom Track an order. Not needed with the key that created the order.
Last-Event-IDOptional
stringThe id of the last event you received, sent back unchanged. The stream skips what you already have.
curl -N https://api.mindswap.io/v1/orders/$ORDER_ID/events \
    --get \
    -d cap=$CAP
id: 0.0
data: { "type": "order", "order": { "id": "MS-7HK2PQ", "version": 0, … } }

data: { "type": "heartbeat", "version": 0 }

Track an order

No key
POST/v1/orders/track

Opens any order from any device with its ID and payout address. A missing order and a wrong address both answer 404 not_found.

Body

orderIdRequired
stringThe order ID, for example MS-7HK2PQ.
payoutAddressRequired
stringThe address the order pays out to, exactly as it was given.
curl https://api.mindswap.io/v1/orders/track \
    -H "content-type: application/json" \
    -d @- <<JSON
{ "orderId": "$ORDER_ID", "payoutAddress": "$PAYOUT_ADDRESS" }
JSON
{
  "order": { "id": "MS-7HK2PQ", "status": "awaiting_deposit", … },
  "cap": "1795022983.Z4Pq…"
}

Response

order
OrderViewThe same order as Read an order.
cap
string | nullRead-only access for 24 h. Pass it as ?cap= to read the order and its events.

Report a problem

No key
POST/v1/orders/{id}/issues

One flow for every route. Prove the order the same way as tracking: its payout address, a cap, or the key that created it.

Body

kindRequired
enumrefund, not_received, wrong_network, wrong_amount or other.
payoutAddressOptional
stringThe order's payout address, as proof. Leave it out when you send ?cap= or the key.
detailsOptional
stringWhat happened, in the user's words. Up to 4,000 characters.
depositTxHashOptional
stringThe deposit transaction, when the user has it.
refundAddressOptional
stringWhere to send a refund, with refundMemo when the network needs one.
curl https://api.mindswap.io/v1/orders/$ORDER_ID/issues \
    -H "content-type: application/json" \
    -d @- <<JSON
{
  "kind": "not_received",
  "payoutAddress": "$PAYOUT_ADDRESS",
  "details": "Sent the deposit two hours ago. Nothing arrived yet."
}
JSON
{
  "id": "7e33efd4-931e-4272-ada0-8a5261568ca5",
  "kind": "not_received",
  "state": "received",
  "timeline": [{ "at": "2026-11-17T17:23:40Z", "text": "We received your request." }],
  "nextUpdateBy": "2026-11-18T05:23:40Z",
  "action": null
}

Response

state
enumreceived, in_progress, needs_info or resolved.
timeline
object[]What happened so far, in plain words, oldest first.
nextUpdateBy
string | nullWhen we answer next at the latest. Null once resolved.

List networks

No key
GET/v1/networks

Every network with at least one swappable asset, most assets first, with how many assets each has. Use an `id` as the `network` filter of `listAssets`. `family` is the address format MindSwap checks (`evm`, `bitcoin`, `solana`, ...). `logoUri` is `null` while no official logo is stored. Cached for a minute with an `ETag`. No key needed. **Rate limits.** 120 a minute per IP (bursts up to 60). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

curl https://api.mindswap.io/v1/networks
{
  "networks": [
    {
      "id": "ethereum",
      "name": "Ethereum",
      "family": "evm",
      "logoUri": "https://mindswap.io/logos/db6927db9f5dbf556d647ade68d2d1d0.svg",
      "assetCount": 618
    },
    {
      "id": "bnb-chain",
      "name": "BNB Smart Chain",
      "family": "evm",
      "logoUri": "https://mindswap.io/logos/97d00b983d6baf023e6b4a8e5d700394.svg",
      "assetCount": 401
    }
  ]
}

Response

networks
object[]

List the orders made with this key

API key
GET/v1/orders

The orders created with the calling API key, newest first, a page at a time. Pass `nextCursor` back as `cursor` for the next page; it is null on the last page. Each order is the same view `getOrder` answers. **Auth.** An API key; the list holds only that key's own orders. **Rate limits.** 120 a minute per API key (bursts up to 30). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

Query

statusOptional
enumOnly orders in this status (`awaiting_deposit`, `completed`, …).
limitOptional
numberOrders per page, 1 to 100.
cursorOptional
string`nextCursor` from the previous page.
curl https://api.mindswap.io/v1/orders \
    -H "x-api-key: $MINDSWAP_API_KEY"
{
  "orders": [
    {
      "id": "MS-7HK2PQ",
      "version": 1,
      "type": "fixed",
      "pickedBy": "mind",
      "route": {
        "provider": "fixedfloat",
        "venue": "mind",
        "kind": "exchange",
        "rateType": "fixed",
        "from": "btc:bitcoin",
        "to": "usdt:tron",
        "amountIn": "0.01",
        "amountOut": "618.368",
        "fees": {
          "network": {
            "amount": "0.75919",
            "asset": "usdt:tron"
          },
          "provider": {
            "amount": "0",
            "asset": "usdt:tron"
          },
          "platform": {
            "amount": "0",
            "asset": "usdt:tron"
          },
          "totalUser": {
            "amount": "0.75919",
            "asset": "usdt:tron"
          }
        },
        "feesEstimated": true,
        "etaSeconds": 1200,
        "min": "0.0001599",
        "max": "0.2422837"
      },
      "payout": {
        "address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
        "memo": null
      },
      "refund": {
        "address": "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
        "memo": null
      },
      "deposit": {
        "address": "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
        "memo": null,
        "amount": "0.01",
        "expiresAt": "2026-11-18T17:12:30.000Z",
        "expiresSource": "provider",
        "received": null
      },
      "status": "awaiting_deposit",
      "steps": [
        {
          "status": "awaiting_deposit",
          "at": "2026-11-18T16:52:30.000Z"
        }
      ],
      "amountOut": "618.368",
      "refunded": null,
      "recipients": null,
      "usd": {
        "btc:bitcoin": "61849.88",
        "usdt:tron": "1"
      },
      "notices": [],
      "txs": [],
      "issue": null,
      "points": null,
      "viewer": {
        "role": "api_key",
        "canClaim": false,
        "owned": false
      },
      "createdAt": "2026-11-18T16:52:30.000Z",
      "updatedAt": "2026-11-18T16:52:30.000Z"
    }
  ],
  "nextCursor": null
}

Response

orders
object[]
nextCursor
any

Check whether a pair can be swapped

No key
GET/v1/pairs

Whether any enabled provider can swap `from` into `to`, and which: one route per provider and kind (`exchange`, `private`, `public`) with the rate types it offers for these two assets. MIND routes show as provider `mind`. Answered from the catalog alone, so no provider is asked and nothing is priced: min, max and amounts come only from `getQuotes`. A pair nobody serves answers `available: false` with no routes. No key needed. **Rate limits.** 600 a minute per IP (bursts up to 120). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

Query

fromRequired
stringThe asset to send, `<symbol>:<network>` (`btc:bitcoin`), from `listAssets`.
toRequired
stringThe asset to receive (`usdt:tron`).
curl https://api.mindswap.io/v1/pairs
{
  "from": "btc:bitcoin",
  "to": "usdt:tron",
  "available": true,
  "routes": [
    {
      "provider": "changenow",
      "kind": "exchange",
      "rateTypes": [
        "float"
      ]
    },
    {
      "provider": "fixedfloat",
      "kind": "exchange",
      "rateTypes": [
        "float",
        "fixed"
      ]
    }
  ]
}

Response

from
string
to
string
available
boolean
routes
object[]

Read your key's partner fee earnings

API key
GET/v1/partner/earnings

The partner fee set on the calling key (0 to 300 basis points, set on mindswap.io/app/api) and what it has earned. `credited` is what completed orders added to the account's USDT balance, withdrawn through payouts. `pending` is the fee on open orders at their quoted value, an estimate that becomes `credited` only when the order completes. Needs the API key. **Rate limits.** 60 a minute per API key (bursts up to 20). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

curl https://api.mindswap.io/v1/partner/earnings \
    -H "x-api-key: $MINDSWAP_API_KEY"
{
  "keyId": "0b9f3c52-6d1e-4a7b-9c8d-2e5f1a4b7c90",
  "currency": "USDT",
  "partnerFeeBps": 100,
  "credited": "45",
  "pending": "12.5",
  "completedOrders": 3,
  "openOrders": 1
}

Response

keyId
string
currency
string
partnerFeeBps
number
credited
string
pending
string
completedOrders
number
openOrders
number

Estimate each wallet of a multi-wallet swap

No key
POST/v1/quotes/recipients

For a multi-wallet order (the output split over 1 to 1000 payout wallets): what each wallet would receive and the smallest payout its exchange allows. Only a `float` route of MIND or one of its exchange venues takes several wallets. Send each wallet's `percent` (up to 2 decimals, all adding up to exactly 100) and `venue` (null for MIND), in the order you will send them to `createOrder`. `ok: false` marks a wallet its venue cannot pay out; `createOrder` would answer `recipient_below_min`. Read only: no order is made. No key needed. **Rate limits.** 60 a minute per IP (bursts up to 20). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

Body

routeIdRequired
string
recipientsRequired
object[]
curl -X POST https://api.mindswap.io/v1/quotes/recipients \
    -H "content-type: application/json" \
    -d '{"routeId":"r1.k1.h3-EUyT9VmfLOIpC62z7AJZRuTxDh6H5OY9OUG4jlf…","recipients":[{"percent":"60","venue":null},{"percent":"40","venue":null}]}'
{
  "recipients": [
    {
      "ok": true,
      "amountOut": "371.2743819",
      "minimum": "5.5"
    },
    {
      "ok": true,
      "amountOut": "247.0162546",
      "minimum": "5.5"
    }
  ]
}

Response

recipients
object[]

Points program and cashback tiers

No key
GET/v1/rewards/program

The points program: `pointsPerUsd` points per US dollar of completed volume, and the tiers by points with their cashback and referral shares in basis points (1500 = 15 %). Orders made with a commercial API key earn no points. No key needed. **Rate limits.** 120 a minute per IP (bursts up to 40). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

curl https://api.mindswap.io/v1/rewards/program
{
  "pointsPerUsd": 100,
  "buybackBps": 4000,
  "tiers": [
    {
      "tier": 1,
      "minPoints": 0,
      "cashbackBps": 1500,
      "referralBps": 1000
    },
    {
      "tier": 2,
      "minPoints": 10000000,
      "cashbackBps": 2500,
      "referralBps": 2500
    },
    {
      "tier": 3,
      "minPoints": 50000000,
      "cashbackBps": 3500,
      "referralBps": 3500
    },
    {
      "tier": 4,
      "minPoints": 100000000,
      "cashbackBps": 5000,
      "referralBps": 5000
    }
  ]
}

Response

pointsPerUsd
number
buybackBps
number
tiers
object[]

Read this API key's usage

API key
GET/v1/usage

The calling key's own traffic: requests, errors (4xx and 5xx except 429) and rate-limited answers, per hour for `24h` or per UTC day for `7d`, oldest first. The last bucket is still running. `limit` is the key's own bucket (`perMinute`, `burst`); it is null while the key is inactive and the anonymous per-IP limits apply. A key becomes active when an order made with any of the account's keys completes. **Auth.** An API key. **Rate limits.** 120 a minute per API key (bursts up to 30). Over a limit the answer is `429 rate_limited` with `retryAfterMs` and a `Retry-After` header. Wait that long, then call again.

Query

windowOptional
enum`24h` (hourly buckets, the default) or `7d` (daily buckets).
curl https://api.mindswap.io/v1/usage \
    -H "x-api-key: $MINDSWAP_API_KEY"
{
  "window": "24h",
  "buckets": [
    {
      "start": "2026-11-18T16:00:00.000Z",
      "requests": 412,
      "errors": 3,
      "rateLimited": 0
    },
    {
      "start": "2026-11-18T17:00:00.000Z",
      "requests": 128,
      "errors": 0,
      "rateLimited": 2
    }
  ],
  "totals": {
    "requests": 540,
    "errors": 3,
    "rateLimited": 2
  },
  "lastUsedAt": "2026-11-18T17:41:09.000Z",
  "limit": {
    "perMinute": 1200,
    "burst": 200
  }
}

Response

window
enumOne of 24h, 7d.
buckets
object[]
totals
object
lastUsedAt
date-time | null
limit
object | null

Errors

Every error has the same shape. Branch on code, show message, and quote requestId to support.

Any call

invalid_request
400
An input is missing or malformed. details names the field.Fix the field that details names and send again. Sending it unchanged fails the same way.
unauthorized
401
The call needs proof it did not carry: the API key that owns the resource, or for an order its payout address or cap.For an order, send its payout address (or the cap from tracking). Swaps never need an API key. For an endpoint that reads your key (orders list, usage, partner earnings), send a valid msk_live_ key.
not_found
404
Nothing matches this ID with this proof. A wrong order ID and a wrong payout address answer the same.Check the order ID and the payout address with the user. Do not guess: attempts are limited per order.
rate_limited
429
Too many requests from this caller (per IP, or per key once the key is active).Wait retryAfterMs milliseconds, then send the same request again.
service_paused
503
MindSwap paused this briefly (new orders or this endpoint).Wait retryAfterMs, then try again.
internal
500
An unexpected error on the MindSwap side.Try again once a little later. A create may only be resent with the same idempotency key. If it repeats, contact support with requestId.

Quotes

route_expired
410
The routeId is past its expiresAt. Nothing was created.Quote again and confirm the new route with the user.
quote_moved
409
The rate changed or the route stopped running before the order was made. Nothing was created. details.route is the fresh route, when one exists.Show the fresh route to the user. If they accept, create with its routeId and a new idempotency key (the old key is bound to the old route). If there is no fresh route, quote again.
pair_unavailable
422
No provider can swap this pair right now, or the pair is not listed.Try another pair, or the same pair later.
amount_out_of_range
422
The amount is outside what the provider accepts right now. Nothing was created.Quote again and pick an amount within the route's min and max.

Creating an order

address_invalid
422
A payout or refund address is not valid on its network. details.field says which, when it was checked.Ask the user for that address again. Never correct, guess or invent it.
memo_required
422
The address needs a memo (destination tag) on this network.Ask the user for the memo and send it with the address.
recipient_below_min
422
In a multi-wallet order, a wallet's share is below its exchange's minimum payout. details.below[].index lists them.Raise those shares or remove those wallets, then create again.
idempotency_mismatch
422
This idempotency key was already used with other inputs.To retry, send exactly the original inputs with the same key. For a new swap the user confirmed, use a new key.
create_in_progress
409
An order with this idempotency key is still being created.Wait retryAfterMs, then send the same request with the same key. It returns that order and never makes a second one.
create_in_doubt
502
The provider may or may not have made the order, and MindSwap cannot tell which.STOP. Do not create again for this swap, with any key, and tell the user not to send funds. Contact MindSwap support with requestId.
provider_rejected
502
The provider refused the order. Nothing was created and nothing is owed. "This route needs browser details" means the end user's language and time zone were missing.Quote again and pick another route. Send the end user's own language and time zone (Accept-Language, X-Client-Timezone) with the create.
too_many_open_orders
429
This caller already has as many unpaid orders open as it may (the limit is in the message). Nothing was created and no provider was asked.Pay one of the open orders, or wait until one expires, then create again. Do not retry in a loop: the answer stays the same until an order is paid or expires.
provider_busy
503
The provider behind this route had no capacity for a new order within about 10 seconds. Nothing was created.Wait retryAfterMs, then send the same request again with the same idempotency key, or pick another route.

Account and keys

order_not_claimable
409
This order cannot be added to this account.Tell the user. Retrying does not help.
already_claimed
409
The order already belongs to a MindSwap account.Sign in to that account to see it.
duplicate
409
That item already exists.Use the existing one. Do not create it again.
stale_version
412
The item changed after you read it.Read it again, apply the change to the fresh copy, and send again.
wallet_linked_elsewhere
409
This wallet is linked to another MindSwap account.Unlink it from the other account first, or use another wallet.
key_revoked
409
This API key was revoked, or rotated with a grace period, so its settings no longer change. Its replacement holds them.Change the setting on the key that replaced it, or create a new key.

Payouts

has_open_balance
409
The account still holds a balance or an open payout.Withdraw the balance and let open payouts finish first.
payout_below_minimum
422
The withdrawal is below the minimum payout.Wait until the balance reaches the minimum, then withdraw.
insufficient_balance
409
The balance is lower than the amount asked for.Ask for at most the available balance.
payout_open
409
A payout is already in progress for this account.Wait until it finishes, then try again.
payouts_frozen
503
Payouts are paused for a check. Balances are safe.Try again later.

Rate limits

One limit for every key, counted per key. Until your account completes its first order, a key gets the per-IP limits below. A limit you hit answers 429 rate_limited with retryAfterMs.

Every active key
1,200 calls/min
Burst
200 calls
Get quotes
120 a minute per IP
Create an order
20 a minute per IP
Track an order
30 a minute per IP
Per order: 10 at once, then 1 every 6 min

Webhooks

Not live yet

Signed POSTs to your endpoint are planned. Until they launch, follow each order live with GET /v1/orders/{id}/events.

  • order.deposit_detected
  • order.completed
  • order.refunded

Code examples

One swap, from quote to deposit instructions. Run it on your server with MINDSWAP_API_KEY, PAYOUT_ADDRESS and REFUND_ADDRESS set.

const api = 'https://api.mindswap.io/v1'
const headers = { 'x-api-key': process.env.MINDSWAP_API_KEY }

// 1. Quote: MIND's fixed pick for 0.1 BTC to ETH
const quote = await fetch(`${api}/quotes?from=btc:bitcoin&to=eth:ethereum&amountIn=0.1`, { headers })
  .then((r) => r.json())
if (!quote.mind.fixed) throw new Error('No fixed route for this pair right now')

// 2. Create, once per confirmation. Keep the key: a retry with it never makes a second order.
const order = await fetch(`${api}/orders`, {
  method: 'POST',
  headers: { ...headers, 'content-type': 'application/json', 'idempotency-key': crypto.randomUUID() },
  body: JSON.stringify({
    routeId: quote.mind.fixed,
    pickedBy: 'mind',
    payout: { address: process.env.PAYOUT_ADDRESS, memo: null },
    refund: { address: process.env.REFUND_ADDRESS, memo: null },
    ref: null,
  }),
}).then((r) => r.json())
if (order.error) throw new Error(`${order.error.code}: ${order.error.message}`)

// 3. Deposit instructions
console.log(`Send ${order.deposit.amount} BTC to ${order.deposit.address}`)