# Flow helpers

One call runs a whole order: quote, checks, signatures, order, escrow if the route has one, then watching to the end. Use these unless you need your own screens at each step.

```ts
import { createMaxyClient } from '@maxy-labs/sdk/core';
import { buyBtcWithEvm } from '@maxy-labs/sdk/evm';
import { createWalletClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';

// A throwaway wallet; live, the user's wallet client.
const wallet = createWalletClient({ account: privateKeyToAccount(generatePrivateKey()), chain: base, transport: http() });

const done = await buyBtcWithEvm({
  client: createMaxyClient(), // reads MAXY_API_KEY
  wallet,
  from: 'USDC on base',
  amount: '20',               // or receive: '0.0001' for exact BTC
  recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
  onProgress: (state, ctx) => console.log(state, ctx.orderId ?? ''),
});
console.log(done.order.state, done.bitcoinTxid);
```

| Helper | From |
| --- | --- |
| `buyBtcWithEvm` | `@maxy-labs/sdk/evm` |
| `buyBtcWithSolana` | `@maxy-labs/sdk/solana` ([Pay with SOL](https://maxy.co/docs/other-coins#pay-with-sol)) |
| `sellBtc` | `@maxy-labs/sdk/bitcoin` ([Sell BTC](https://maxy.co/docs/sell-btc)) |

Each reports the same progress words, and stops at `refundable`, because nothing more happens without the user. A helper stores nothing: keep the order id from `onProgress` and pass `resume: { orderId }` to pick up.

A page with a publishable key cannot place orders, so pass `placeOrder` pointing at your server.

## Testing

Test your code with no network. `@maxy-labs/sdk/testing` gives the same envelopes as the API, one fixture per error code, and a simulator that walks an order through any states. `mswHandlers` plugs into MSW.

```ts
import { createMaxyClient } from '@maxy-labs/sdk/core';
import { SandboxSimulator, createMockFetch, errorFixture } from '@maxy-labs/sdk/testing';

const sim = new SandboxSimulator();
const id = sim.order(['pending', 'in_progress', 'refundable', 'refunded']);
const client = createMaxyClient({ fetch: createMockFetch({ simulator: sim }).fetch });

sim.next(id, 'refundable');
await client.orders.get(id);                                     // state: refundable

const down = createMaxyClient({ fetch: createMockFetch({ failWith: 'rate_limited' }).fetch, maxRetries: 0 });
```

For a real API with nothing behind it, use the [sandbox](https://maxy.co/docs/sandbox).

Every night the server walks one order through each failure branch on the sandbox: see the last run on [Status](https://maxy.co/status).

---
Source: https://maxy.co/docs/flow-helpers (Maxy Docs › SDK › Use it)
