# Sell BTC

Sell BTC for a coin on an EVM chain. The solver locks the payout in the settler before the user sends any BTC. The user pays one Bitcoin output, and a proof releases the payout to them.

The EVM wallet that receives the payout signs one message. This needs no sign-in. `fromAddress` is any Bitcoin address of the payer. The samples use the setup from [Get a quote](https://maxy.co/docs/buy-btc#get-a-quote).

```sh
curl -s -G "$BASE/quote" -H "x-maxy-key: $MAXY_API_KEY" -d from=BTC --data-urlencode "to=USDC on base" -d amount=0.0005 \
  -d fromAddress="$MY_BTC_ADDRESS" -d toAddress="$WALLET" > quote.json
INTENT_SIG=$(cast wallet sign --private-key "$TEST_WALLET_KEY" --data "$(jq -c '.steps[] | select(.id == "intent") | .typedData' quote.json)")
curl -s -X POST "$BASE/orders" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d "$(jq -c --arg sig "$INTENT_SIG" '{order: .order, signatures: {intent: $sig}}' quote.json)" > placed.json
DEPOSIT="$BASE$(jq -r '.next.path | ltrimstr("/")' placed.json)"       # the path starts with /, as BASE ends
until curl -s "$DEPOSIT" | jq -e .ready > /dev/null; do sleep 3; done
curl -s "$DEPOSIT" | jq '{address, sats, bitcoinUri, expiresAt}'
```

```ts
import { createMaxyClient } from '@maxy-labs/sdk/core';
import { sellBtc } from '@maxy-labs/sdk/bitcoin';

const sell = await sellBtc({
  client: createMaxyClient(), // reads MAXY_API_KEY
  wallet: { getAddress: async () => account.address, signTypedData: (t) => account.signTypedData(t), sendTransaction: async () => { throw new Error('a sale sends nothing here'); } },
  to: 'USDC on base',
  amount: '0.0005',
  onProgress: (state) => console.log(state),
});
console.log(sell.paymentInstructions); // { address, sats, expiresAt, bip21 }
const done = await sell.done;
console.log(done.order.state);
```

```python
import time

quote = requests.get(f"{BASE}/quote", headers={"x-maxy-key": KEY}, params={
    "from": "BTC", "to": "USDC on base", "amount": "0.0005", "fromAddress": btc_address, "toAddress": account.address,
}).json()
step = next(s for s in quote["steps"] if s["id"] == "intent")
signature = "0x" + bytes(account.sign_message(encode_typed_data(full_message=step["typedData"])).signature).hex()
placed = requests.post(f"{BASE}/orders", headers={"x-maxy-key": KEY}, json={"order": quote["order"], "signatures": {"intent": signature}}).json()
while True:  # the path starts with /, as BASE ends
    deposit = requests.get(BASE + placed["next"]["path"].removeprefix("/")).json()
    if deposit["ready"]:
        break
    time.sleep(3)
print(deposit["address"], deposit["sats"], deposit["bitcoinUri"], deposit["expiresAt"])
```

Poll until `ready` is `true`, then show the address. `bitcoinUri` is the QR code. In the sandbox the address is a testnet one: pay nothing, and the order walks by itself.

> **Pay once, exactly, on time.** One output of exactly `sats` to `address`. Live orders allow 19 Bitcoin blocks, about 3 hours. Speeding up a stuck payment is fine if it keeps the amount and address; never lower or split it.

Each order is at least about $10, up to your key's cap, with three open sell orders per wallet: more answers `rate_limited` until they are paid or expire. `insufficient_liquidity` means the solver cannot pay this size now. `deposit_address_unverified` means the payout is not escrowed for the user: **do not pay**, and start again.

A wrong or late payment: [Failed sells](https://maxy.co/docs/when-it-fails#failed-sells).

---
Source: https://maxy.co/docs/sell-btc (Maxy Docs › Swaps › Routes)
