# 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.

```ts
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. The solver opens its offer on chain.
2. The SOL locks in the program's escrow.
3. The solver pays the BTC to the user's address.
4. 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](https://maxy.co/docs/signature-screen#signing-screen).

## Limits and timing

| Rule | Value |
| --- | --- |
| Smallest order | About $2 |
| Largest order | Your key's cap: [Order size](https://maxy.co/docs/keys-and-limits#order-size) |
| An offer the user never funds | Expires after 10 minutes: `quote_expired`, quote again |
| An escrow whose BTC is never proven | Refunds the user's wallet when it expires |
| BTC addresses, live | `bc1q…` or `bc1p…` |
| BTC addresses, sandbox | `bc1q…` only |

The program and its Bitcoin node are listed on [Contracts](https://maxy.co/docs/contracts). A Solana order can also end `expired` or `failed`: see [Order states](https://maxy.co/docs/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](https://maxy.co/docs/react-and-python).

---
Source: https://maxy.co/docs/pay-with-sol (Maxy Docs › User flows and examples › Swaps)
