Find something... ⌘K

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.

What you actually pay
What arrivesnothing added after you sign the quote
Valid for 60 s
A quote is what you receive

Price, then quote

With a test key, this runs as it is. Live, the wallet and the Bitcoin address are your user's.

TypeScript Copy
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);
ParameterMeaning
from, toA coin in words (USDC on base, SOL, BTC), a CAIP-19 id, or { chain, token }
amountWhole coins to send, as a string. A bigint is the smallest unit
receiveInstead of amount: the exact BTC to receive, in whole BTC
fromAddress, toAddressWho pays and who receives. A quote needs both; without them GET /quote answers 400 invalid_input
slippageBpsHow far the price may move before the escrow opens. Default 50
scenarioSandbox only: force an outcome

What a quote says

FieldMeaning
quoteIdBecomes the order id
toAmountWhat arrives, in the smallest unit, with every cost in. formatted has it in words
expiresAtUnix seconds. Count down with quotes.msUntilExpiry, which uses Maxy's clock, not the device's
stepsWhat the wallet does, in order. null when something stops the order
signingThe same signatures in one shape on every route
issuesWhat is short: balance, allowance or orderCap, each null when fine
liquidityAvailablefalse when Maxy cannot fill this size now

Always show the amounts and keep the button live, then refuse at the click:

  • issues.orderCap is set above your key's order size cap. It carries capUsd and a message to show, and steps is null. Offer the capped amount on the same screen.
  • liquidityAvailable: false answers 200 with no steps, and names no size limit. Offer a smaller amount; an aggregator ranks the next source.
  • issues.balance says the wallet holds too little. The sandbox reads no balances, so force it with scenario: '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.

TypeScript Copy
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.