SDK / Using the SDK
Request quotes
Get prices and quotes with the SDK, read what a quote says about funds, size and liquidity, and keep it fresh until the user signs. It is for developers building the amount and confirm screens.
A price is for display: no wallet, nothing reserved. A quote is the executable amount for one order about to be placed: it names who pays and who receives, and is valid for 60 seconds. Both answer at any size above the route's minimum (546 sats buying BTC). More on the difference: Price vs quote.
Price, then quote
With a test key, this runs as it is. Live, the wallet and the Bitcoin address are your user's.
import { createMaxyClient } from 'maxy-labs/core'; import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; const maxy = createMaxyClient(); // reads MAXY_API_KEY const account = privateKeyToAccount(generatePrivateKey()); // a throwaway wallet const btcAddress = 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'; // While the user types. const price = await maxy.prices.get({ from: 'USDC on base', to: 'BTC', amount: '20' }); console.log(price.formatted?.receive); // 0.00031776 BTC // When the user moves to confirm. let quote = await maxy.quotes.get({ from: 'USDC on base', to: 'BTC', amount: '20', fromAddress: account.address, toAddress: btcAddress }); console.log(quote.quoteId, quote.toAmount, quote.liquidityAvailable, quote.issues); console.log(quote.steps?.map((s) => `${s.id}:${s.kind}`)); // [ 'witness:signature', 'order:post' ] // Renew it shortly before it lapses. if (maxy.quotes.msUntilExpiry({ expiresAt: quote.expiresAt ?? 0 }) < 5_000) quote = await maxy.quotes.refresh(quote);
| Parameter | Meaning |
|---|---|
from, to | A coin in words (USDC on base, SOL, BTC), a CAIP-19 id, or { chain, token } |
amount | Whole coins to send, as a string. A bigint is the smallest unit |
receive | Instead of amount: the exact BTC to receive, in whole BTC |
fromAddress, toAddress | Who pays and who receives. A quote needs both; without them GET /quote answers 400 invalid_input |
slippageBps | How far the price may move before the escrow opens. Default 50 |
scenario | Sandbox only: force an outcome |
What a quote says
| Field | Meaning |
|---|---|
quoteId | Becomes the order id |
toAmount | What arrives, in the smallest unit, with every cost in. formatted has it in words |
expiresAt | Unix seconds. Count down with quotes.msUntilExpiry, which uses Maxy's clock, not the device's |
steps | What the wallet does, in order. null when something stops the order |
signing | The same signatures in one shape on every route |
issues | What is short: balance, allowance or orderCap, each null when fine |
liquidityAvailable | false when Maxy cannot fill this size now |
Always show the amounts and keep the button live, then refuse at the click:
issues.orderCapis set above your key's order size cap. It carriescapUsdand amessageto show, andstepsisnull. Offer the capped amount on the same screen.liquidityAvailable: falseanswers200with no steps, and names no size limit. Offer a smaller amount; an aggregator ranks the next source.issues.balancesays the wallet holds too little. The sandbox reads no balances, so force it withscenario: 'insufficient_funds'.
The flow helpers apply the first two for you and throw AmountOutOfRangeError or UnfillableError: Flow helpers.
Expiry
An order from a quote older than 60 seconds is refused with 409 quote_expired, before anything is sent; the SDK throws QuoteExpiredError. Get a new quote and sign that. An order whose price moved past the quote's band answers 409 quote_mismatch, the same class. quotes.refresh(quote) asks the same question again.
Many at once
quotes.batch sends up to 20 requests in one call. Each result has its own status and requestId, and a quote or an error; one failing does not fail the rest.
const { results } = await maxy.quotes.batch([ { from: 'ETH on base', to: 'BTC', amount: '0.01' }, { from: 'SOL', to: 'BTC', amount: '1' }, { from: 'DOGE', to: 'BTC', amount: '1' }, ]); for (const r of results) console.log(r.index, r.status, r.quote?.formatted?.receive ?? r.error?.code); // 0 200 0.000278 BTC // 1 200 0.00116411 BTC // 2 400 invalid_input
A price that stays current while the user watches: prices.stream, on Speed and latency. Placing the order once the user signs: Flow helpers, or step by step on Buy BTC.