# First order

Run one order from nothing to `completed`, with a throwaway wallet that holds nothing. It takes three commands and about a minute, needs no sign-up and no SDK, and nothing real moves.

## Get a test key

One call gives you a test key, with no sign-up. It runs the same API with nothing real behind it, and no wallet needs funds. The button at the foot of any page here gives one too, and fills it into these samples. It looks like `mxk_test_` and 32 letters and digits.

```sh
export BASE=https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api
export MAXY_API_KEY=$(curl -s -X POST "$BASE/sandbox/keys" -H 'content-type: application/json' -d '{}' | jq -r .secretKey)
curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/key"
```

```ts
const BASE = 'https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api';
const keys = await fetch(`${BASE}/sandbox/keys`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }).then((r) => r.json());
const key = await fetch(`${BASE}/key`, { headers: { 'x-maxy-key': keys.secretKey } }).then((r) => r.json());
console.log(keys.secretKey, key.sandbox); // mxk_test_…, true: export it as MAXY_API_KEY
```

```python
import requests

BASE = "https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api"
secret = requests.post(f"{BASE}/sandbox/keys", json={}).json()["secretKey"]
print(secret, requests.get(f"{BASE}/key", headers={"x-maxy-key": secret}).json()["sandbox"])  # mxk_test_…, True
```

The answer shows `"kind": "secret"`, your `orderCapUsd` and `"sandbox": true`. A cut-off key answers `invalid_api_key`; a call with no key answers `auth_required`.

## Get a price

What 0.01 ETH on Base buys in BTC now. No wallet is needed, and nothing is reserved.

```sh
curl -sG -H "x-maxy-key: $MAXY_API_KEY" "$BASE/price" --data-urlencode "from=ETH on base" -d to=BTC -d amount=0.01
```

Or ask it here, from this page:

## Run the order

Each sample needs one thing first, and nothing from the kit:

- **curl:** `jq` and Foundry's `cast`.
- **TypeScript:** `npm install viem`. Node 22.18 or newer runs the `.ts` file as it is. On older Node, name it `sandbox-fetch.mjs`.
- **Python:** `pip install requests eth-account`.

```sh
#!/usr/bin/env bash
# One whole escrow order in the sandbox with curl, jq and Foundry's cast. Run it with a test key: nothing real happens,
# and the wallet is a throwaway made here. It never broadcasts: `transaction.simulatedHash` stands in for the hash.
#   export MAXY_API_KEY=mxk_test_…
set -euo pipefail
BASE=${MAXY_API_BASE:-https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api}
BTC=bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
KEY=$(cast wallet new --json | jq -r '.[0].private_key')
WALLET=$(cast wallet address --private-key "$KEY")

QUOTE=$(curl -sG -H "x-maxy-key: $MAXY_API_KEY" "$BASE/quote" --data-urlencode "from=ETH on base" -d to=BTC -d amount=0.001 -d fromAddress="$WALLET" -d toAddress="$BTC" ${SCENARIO:+-d scenario="$SCENARIO"})
echo "$QUOTE" | jq '{sandbox, route, toAmount, steps: [.steps[]?.id]}'
TYPED=$(echo "$QUOTE" | jq -c '.steps[] | select(.id=="intent") | .typedData | .types.EIP712Domain = [{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}]')
SIG=$(cast wallet sign --private-key "$KEY" --data "$TYPED")

PLACED=$(curl -s -X POST -H "x-maxy-key: $MAXY_API_KEY" -H 'content-type: application/json' "$BASE/orders" -d "$(echo "$QUOTE" | jq -c --arg s "$SIG" '{order, signatures: {intent: $s}}')")
echo "$PLACED" | jq '{orderId, transaction, simulation}'
ID=$(echo "$PLACED" | jq -r .orderId)
HASH=$(echo "$PLACED" | jq -r .transaction.simulatedHash)

curl -s -X POST -H "x-maxy-key: $MAXY_API_KEY" -H 'content-type: application/json' "$BASE/orders/submit" -d "$(echo "$QUOTE" | jq -c --arg h "$HASH" --arg s "$SIG" '{order, signatures: {intent: $s}, txHash: $h}')" | jq .
for _ in 1 2 3 4 5 6 7 8; do
  STATUS=$(curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/orders/$ID")
  echo "$STATUS" | jq -c '{state, btcTxId, sandbox}'
  [ "$(echo "$STATUS" | jq -r .isComplete)" = true ] && break
  sleep 4
done
```

```ts
// One whole gasless order in the sandbox with fetch and viem, no SDK. Run it with a test key: nothing real happens, and
// the wallet is a throwaway made here. Node 22.18 or newer runs the .ts file as it is (older: name it sandbox-fetch.mjs).
//   npm install viem
//   export MAXY_API_KEY=mxk_test_…
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

const BASE = process.env.MAXY_API_BASE ?? 'https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api';
const api = async (path: string, body?: unknown) => {
  const res = await fetch(BASE + path, {
    method: body ? 'POST' : 'GET',
    headers: { 'x-maxy-key': process.env.MAXY_API_KEY!, 'content-type': 'application/json' },
    body: body ? JSON.stringify(body) : undefined,
  });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.message}`);
  return json;
};
const wallet = privateKeyToAccount(generatePrivateKey()); // a throwaway wallet that holds nothing

const quote = await api('/quote?' + new URLSearchParams({
  from: 'USDC on base', to: 'BTC', amount: '10', fromAddress: wallet.address,
  toAddress: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4', scenario: process.env.SCENARIO ?? 'success',
}));
if (quote.sandbox !== true) throw new Error('This sample is for a test key (mxk_test_…).');

const signatures: Record<string, string> = {};
for (const step of quote.steps) {
  if (step.kind !== 'signature') continue;
  const { domain, types, primaryType, message } = step.typedData;
  const { EIP712Domain: _domain, ...fields } = types;
  signatures[step.id] = await wallet.signTypedData({ domain, types: fields, primaryType, message });
}

const placed = await api('/orders', { order: quote.order, signatures });
console.log(placed.orderId, placed.route);
for (let i = 0; i < 10; i++) {
  const status = await api(`/orders/${placed.orderId}`);
  console.log(status.state, status.btcTxId);
  if (status.isComplete) break;
  await new Promise((r) => setTimeout(r, 4000));
}
```

```python
# One whole gasless order in the sandbox with requests and eth_account. Run it with a test key: nothing real happens, and
# the wallet is a throwaway made here.
#   export MAXY_API_KEY=mxk_test_…
import os
import time

import requests
from eth_account import Account
from eth_account.messages import encode_typed_data

BASE = os.environ.get("MAXY_API_BASE", "https://whhxyutitykcsdpvdgcd.supabase.co/functions/v1/maxy-api")
HEADERS = {"x-maxy-key": os.environ["MAXY_API_KEY"]}
wallet = Account.create()

quote = requests.get(f"{BASE}/quote", headers=HEADERS, params={
    "from": "USDC on base", "to": "BTC", "amount": "10", "fromAddress": wallet.address,
    "toAddress": "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4", "scenario": os.environ.get("SCENARIO", "success"),
}).json()
assert quote["sandbox"] is True

signatures = {}
for step in quote["steps"]:
    if step["kind"] == "signature":
        typed = step["typedData"]
        signed = Account.sign_message(encode_typed_data(typed["domain"], typed["types"], typed["message"]), wallet.key)
        signatures[step["id"]] = "0x" + signed.signature.hex().removeprefix("0x")

placed = requests.post(f"{BASE}/orders", headers=HEADERS, json={"order": quote["order"], "signatures": signatures}).json()
print(placed)
for _ in range(10):
    status = requests.get(f"{BASE}/orders/{placed['orderId']}", headers=HEADERS).json()
    print(status["state"], status["btcTxId"])
    if status["isComplete"]:
        break
    time.sleep(4)
```

It quotes, signs, places the order and waits. The order reads `pending`, `in_progress` at 8 seconds, and `completed` at 20. Between the quote and the order you have 60 seconds; after that the answer is `quote_expired`, and you quote again.

The same order with the SDK is in your kit's `examples` folder as `first-order.ts` and `first-order.py`. To go step by step, carry on to [Buy BTC](https://maxy.co/docs/buy-btc).

---
Source: https://maxy.co/docs/first-order (Maxy Docs › Start › First swap)
