Skip to main content
This tutorial shows you how to convert Bitcoin (BTC) from a user’s Bitnob wallet into USDT using Bitnob’s built-in swap engine. You’ll go from checking balances to completing a swap and confirming the new stablecoin balance. This is useful when:
  • Users want to lock in the value of their BTC
  • You want to stabilize treasury or float in stablecoins
  • You’re enabling BTC payments but settling in USDT

Key concepts

Swaps allow users to convert volatile assets (BTC) into stable assets (USDT) inside Bitnob. Bitnob handles the exchange rate matching, balance updates, and fees all through simple API calls. By default, every Bitnob account has a BTC and USDT wallet created automatically. You don’t need to create these.

Prerequisites

A Bitnob sandbox or production API key The user must have BTC in their wallet (from on-chain or Lightning) You should track reference IDs for each swap

Step 1: Check BTC wallet balance

To confirm the user has sufficient funds to swap, check their BTC balance with Get Balances, or Get Balance By Currency for a single asset.
If you’re listing balances across every currency:
From the response, look for the wallet with “currency”: “BTC” and check available_balance.

Step 2: Get a swap quote (optional)

You can fetch a live rate before executing the swap with Quotes. This allows you to show the user what they’ll receive.
Example request:
Example response:
The quote expires fast, so read the window from expires_at. You should show this info to the user (rate, amount they’ll receive) before confirming the swap.

Step 3: Execute the quote

To perform the conversion, send a swap request: see Create Order, and Get Order By ID to confirm it settled.
Example request:
Example response:
This response confirms that the BTC was successfully converted to stablecoin and credited to the appropriate wallet.

Step 4: Confirm stablecoin wallet balance

To verify the updated balance, call:
Based on the currency you swapped into. The response includes available_balance, pending_balance, total_balance, and currency.

Handling errors

If the user has insufficient BTC, you’ll get a 422 error with a descriptive message If the quote has expired, you’ll be asked to fetch a new one If the wallet is locked or unavailable, the swap will fail Always log the order id and reference for reconciliation

Best practices

Always fetch a quote before swapping, especially if you’re building a user-facing UI Show a timer for the quote expiry if you use quotes in the front end Clearly display fees and rates for transparency Use unique reference values per swap so you can audit them later Avoid executing back-to-back swaps without confirming balances

Summary

With just a few API calls, you can enable users to:
  • Convert Bitcoin (on-chain or Lightning) into stablecoins
  • Lock in value without withdrawing funds
  • Prepare for local spending, bill payments, or off-ramps
This swap flow is a core part of building any crypto-native experience that wants to bridge volatility and stability.

Next

Track orders and history

Confirm and reconcile the swap.

Handle trading failures

Before you take this to production.