Find something... ⌘K

User flows and examples / Swaps

Any token to BTC

Buy BTC with any token on Base, Arbitrum, BNB Chain, Avalanche, Robinhood Chain, Ethereum, Optimism, Polygon, Linea, zkSync Era, HyperEVM, Mantle, Berachain, Abstract, ApeChain or Monad, on route evm-btc-bridge. It is two legs, both from the user's own wallet: a swap or bridge into the own coin of a chain with a settler, then the escrow buy there, as on Buy BTC. Maxy never holds the coins between the legs. The Maxy app buys BTC with such a token the same way.

The two legs

LegWhat happensWhere
bridgeThe solver's route picker swaps or bridges the token into the settler chain's own coin, paid to the same wallet. Before anything is signed, Maxy checks that the transaction pays that wallet, with a guaranteed minimum out.The token's own chain
escrowThe wallet opens the escrow with that coin, as on evm-btc-escrow. A solver pays the BTC and is paid from escrow on proof.The token's chain when it has a settler (a same-chain swap), Base otherwise

The BTC is sized from the leg's guaranteed minimum, less a little for the escrow transaction's gas. The signed intent fixes it, so toAmountMin equals toAmount. Each leg states its own minimum in legs.

Price it

Name the token by address, or by symbol when it has one on that chain. GET /tokens?chain=ethereum&search=PEPE finds the address. The samples use the setup from Get a quote.

curlTypeScriptPython
Copy
curl -s -G "$BASE/price" -H "x-maxy-key: $MAXY_API_KEY" --data-urlencode "from=USDC on ethereum" -d to=BTC -d amount=50 \ | jq '{route, toAmount, toAmountMin, legs: [.legs[] | {leg, chainId, toChainId, toAmountMin}]}'

A live answer for 50 USDC on Ethereum: route evm-btc-bridge, toAmount 79,487 sats; the bridge leg into ETH on Base guarantees 0.0289 ETH, and the escrow takes at most 0.0286 ETH of it.

Place the order

GET /quote with fromAddress returns the steps in order: approve (the exact amount, only when the allowance is short), intent (signed before any coin moves), order, bridge, escrow, and partnerFee when you asked for one.

  1. 01 Send approve and wait for it to confirm. Sign intent.
  2. 02 POST /orders with the order and the signature. It answers transaction, the swap leg, checked and simulated, and escrow.transaction, for later.
  3. 03 Send transaction before bridgeExpiresAt. Then POST /orders/submit with { order, signatures, bridgeTxHash }.
  4. 04 Follow the bridge path that answer gives until it says ready: true: the coin is in the wallet on the settler chain.
  5. 05 Send escrow.transaction from the same wallet, then POST /orders/submit with { order, signatures, txHash }.

From there the order runs as any buy. GET /status reads the leg while the escrow is not open yet (rawStatus bridge:PENDING, then bridge:DONE), and the escrow after. The SDK's swap.execute and the REST flow buyBtcWithEvm run all five steps.

When a leg does not go through

What happenedWhat the user hasWhat to do
The leg's carrier refunded or failed itTheir token back in the same wallet, from the carrierNothing was escrowed. The signed intent lapses unused
The leg landed and the escrow was never sentThe settler chain's coin in their walletSend the escrow, or keep the coin
No solver filled the escrowTheir coin in escrowTake it back as on any buy: GET /orders/{id}/refund

Tokens with no route

The route picker hands out only a transaction it can check against a price of the solver's own. For a token it has no price for (PEPE and LINK among them), GET /price still answers its number, and GET /quote answers routeAvailable: false, a message and no steps. Show the message, or offer the swap to the chain's own coin first.

Selling BTC for any token

The other way is btc-evm with two legs: the settler pays ETH on Base to the user's wallet, and that wallet bridges it to the token asked for (GET /orders/{id}/bridge). A quote whose bridge the route picker cannot prove has routeAvailable: false, so no BTC is paid for a coin that cannot be delivered.

In the sandbox

A test key runs this route with both legs simulated: the swap leg reads ready: true as soon as its simulatedHash is named, and the order walks to completed after the escrow's.