Find something... ⌘K

User flows and examples / Swaps

Pay with SOL

Buy BTC with SOL from a Solana wallet. The wallet signs a readable request, then the deposit. The SOL goes into the settlement program's escrow, never to a Maxy address, and the BTC goes to the user's own Bitcoin address. Use it when your users hold SOL, or your app already connects Solana wallets such as Phantom, Solflare or Backpack.

Place the order

The SDK's buyBtcWithSolana runs the whole order: quote, signatures, deposit, then watching to the end. The sample runs with a test key once wallet is yours: your wallet adapter, in the shape below.

TypeScript Copy
import { createMaxyClient } from 'maxy-labs/core'; import { buyBtcWithSolana } from 'maxy-labs/solana'; const wallet = { address: publicKey.toBase58(), // the connected wallet signMessage: (text: string) => adapter.signMessage(new TextEncoder().encode(text)), // a readable request signTransaction: (base64: string) => signWithYourAdapter(base64), // signs, does not send; answers base64 }; const done = await buyBtcWithSolana({ client: createMaxyClient(), // reads MAXY_API_KEY wallet, amount: '1', // whole SOL recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4', onProgress: (state) => console.log(state), }); console.log(done.order.state, done.bitcoinTxid);
  1. 01 The solver opens its offer on chain.
  2. 02 The SOL locks in the program's escrow.
  3. 03 The solver pays the BTC to the user's address.
  4. 04 The payment is proven on Solana after one Bitcoin confirmation, and the SOL goes to the solver.

Before the wallet opens, say: "Approve in your wallet. Your SOL is held by the swap program until your BTC is sent." More words on the signature screen.

Limits and timing

RuleValue
Smallest orderAbout $2
Largest orderYour key's cap: Order size
An offer the user never fundsExpires after 10 minutes: quote_expired, quote again
An escrow whose BTC is never provenRefunds the user's wallet when it expires
BTC addresses, livebc1q… or bc1p…
BTC addresses, sandboxbc1q… only

The program and its Bitcoin node are listed on Contracts. A Solana order can also end expired or failed: see Order states.

Over HTTP

GET /quote with from=SOL, sign the quote step's message, POST /orders, sign the deposit it returns, then post it to POST /orders/{id}/steps. Track with GET /status?orderId=…&route=sol-btc. The API checks that the signed deposit is the one it built for this order, signed by the order's wallet, before it sends it.

The other way

BTC to SOL: GET /quote with from=BTC&to=SOL, then follow steps, or use swap.createBtcToSolOrder and swap.settleBtcToSol. The wallet signs three times and needs no SOL: the solver builds and pays for every Solana transaction. If the fresh price is over 0.1% below the quote, the answer is quote_mismatch: quote again.

The same order from React: useBuyBtcWithSolana() in React and Python.