# Pay with USDC

Buy BTC with USDC on Base or Arbitrum, with no gas. The wallet signs once or twice and sends nothing: the solver opens the escrow and pays its gas. Use it when your users hold dollars and no ETH, after a card on-ramp that delivers USDC, or whenever you want the fewest wallet prompts.

| | ETH, BNB, AVAX | USDC on Base and Arbitrum |
| --- | --- | --- |
| Route | `evm-btc-escrow` | `evm-btc-gasless` |
| The wallet signs | The order | A permit when needed, and a transfer bound to this order |
| The wallet sends | One escrow transaction | Nothing |
| `POST /orders` answers | `transaction`, `simulation`, `next` | `submitted: true` |
| After that | You call `POST /orders/submit` | Nothing: the solver opens the escrow |

## Place the order

Quote, sign every `signature` step, and post the signatures keyed by step id. There is no second call. 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" --data-urlencode "from=USDC on base" -d to=BTC -d amount=20 \
  -d fromAddress="$WALLET" -d toAddress="$MY_BTC_ADDRESS" > quote.json
SIGS='{}'
for ID in $(jq -r '.steps[] | select(.kind == "signature") | .id' quote.json); do
  SIG=$(cast wallet sign --private-key "$TEST_WALLET_KEY" --data "$(jq -c --arg id "$ID" '.steps[] | select(.id == $id) | .typedData' quote.json)")
  SIGS=$(echo "$SIGS" | jq -c --arg id "$ID" --arg sig "$SIG" '. + {($id): $sig}')
done
curl -s -X POST "$BASE/orders" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d "$(jq -c --argjson sigs "$SIGS" '{order: .order, signatures: $sigs}' quote.json)"
```

```ts
const q = new URLSearchParams({ from: 'USDC on base', to: 'BTC', amount: '20', fromAddress: account.address, toAddress: btcAddress });
const quote = await fetch(`${BASE}/quote?${q}`, { headers: { 'x-maxy-key': KEY } }).then((r) => r.json());
const signatures: Record<string, string> = {};
for (const step of quote.steps.filter((s: { kind: string }) => s.kind === 'signature')) signatures[step.id] = await walletClient.signTypedData(step.typedData);

const placed = await fetch(`${BASE}/orders`, {
  method: 'POST',
  headers: { 'x-maxy-key': KEY, 'content-type': 'application/json' },
  body: JSON.stringify({ order: quote.order, signatures }),
}).then((r) => r.json());
console.log(placed.orderId, placed.submitted); // submitted: true, nothing to send
```

```python
quote = requests.get(f"{BASE}/quote", headers={"x-maxy-key": KEY}, params={
    "from": "USDC on base", "to": "BTC", "amount": "20", "fromAddress": account.address, "toAddress": btc_address,
}).json()
signatures = {
    s["id"]: "0x" + bytes(account.sign_message(encode_typed_data(full_message=s["typedData"])).signature).hex()
    for s in quote["steps"] if s["kind"] == "signature"
}
placed = requests.post(f"{BASE}/orders", headers={"x-maxy-key": KEY}, json={"order": quote["order"], "signatures": signatures}).json()
print(placed["orderId"], placed["submitted"])  # submitted: True, nothing to send
```

The quote's `route` is `evm-btc-gasless`. The wallet signs a USDC permit, when the allowance is short, and a transfer bound to this order. Steps appear only for a wallet that holds the USDC; otherwise `issues.balance` says what is missing. The sandbox reads no balances, so any wallet works there. Once the escrow opens, the states, webhook and refund rule are the same as paying with ETH: [Track the order](https://maxy.co/docs/buy-btc#track-the-order).

Retrying is safe: the solver opens one escrow per order id. To check the typed data before the wallet opens, compare it with each step's `hash`, as in [Sign](https://maxy.co/docs/buy-btc#sign).

## What the wallet signs

| Step | What it is | When |
| --- | --- | --- |
| `permit` | An EIP-2612 permit for Permit2, for this order's USDC | Only when the Permit2 allowance does not cover the order |
| `witness` | A Permit2 transfer bound to the order id | Every order |

Permit2 is at `0x000000000022D473030F116dDEE9F6B43aC78BA3` on every chain. The transfer covers the settlement amount plus the price band, and only this order can use it. In the sandbox the one signature is a `MaxySandboxOrder`, which authorizes nothing; live, the steps are `permit` when needed, and `witness`. More on each step: [Approvals and permits](https://maxy.co/docs/approvals-and-permits).

Before the wallet opens, say: "Sign in your wallet (once or twice). No gas. Your USDC is held by the swap contract until your BTC is sent." More words on the [signature screen](https://maxy.co/docs/signature-screen#signing-screen).

## If the solver never opens the escrow

The USDC never left the wallet. The signature lapses 2 hours after the quote and the order reads `expired`: no solver committed, so nothing left the wallet and there is nothing to refund. (A committed USDC order that is never paid reads `refundable` and refunds like any other.) Show the user that their USDC is still in their wallet.

## With the SDK

`buyBtcWithEvm` with `from: 'USDC on base'` runs the same order in one call, signatures included: [Flow helpers](https://maxy.co/docs/flow-helpers). After a card on-ramp, quote again once the USDC has landed in the wallet, because a quote names its steps only for a wallet that holds it.

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