swaps (execution), quotes, pools, and tokens (market data).
Constructor
Your integrator API key (
sk_live_ followed by 48 hex chars). Sent on every request as
the x-sdk-key header. Keep it server-side only.Which OneSwap backend to use. The SDK resolves the URL itself — you never pass a raw URL.
swaps.createSwap
Create a swap. Returns a Swap in status awaiting_deposit, carrying the depositParty your end-user must fund and the deadline they must beat.
SDK 1.3.0 added the optional
poolId argument.Pin the swap to a specific visible or API-key-authorized pool. The pool must trade exactly
inSymbol/outSymbol. Pass the poolId returned by quotes.get to settle against the pool
you quoted.Optional hard floor on the output amount. If the swap would return less than this, it is refunded.
{ inSymbol, outSymbol } has no pool available to the API key (no pool for IN/OUT),
if the specified poolId is unavailable or trades a different pair, or OpenSwapExistsError
if the userRef already has an open swap. See Error handling.
oneswap.escrow — the 1.0.0 name for this namespace — still works as a deprecated alias of
the same instance.swaps.getSwap
Fetch the current state of a swap by id. Only returns swaps owned by your integrator.
swaps.waitForSwap
Poll a swap until it reaches a terminal status (returned, refunded, expired, failed, or cancelled), or until the local timeout. Resolves with the final Swap.
Give up after this many milliseconds (default 15 minutes). On timeout the swap may still be
settling — resume with
getSwap(id).swaps.getOpenSwap
Added in SDK 1.2.0.
null if they have none.
A userRef may hold only one open swap at a time — createSwap throws OpenSwapExistsError while one is live. Use this to recover the swap id when you no longer have it: after a process restart, or when the createSwap response was lost in flight.
swaps.cancel
Added in SDK 1.2.0.
Swap (status: 'cancelled').
Only a swap still in awaiting_deposit can be cancelled. Once a deposit has arrived the swap holds funds and must run to completion — cancelling then throws ConflictError (409), and you should waitForSwap instead. Calling this on an already-finished swap returns it unchanged, so it is safe to retry.
getOpenSwap, this is how you recover from a blocked user:
quotes.get
Quote a swap of amount from-tokens into to-tokens. The SDK resolves the pool that trades the pair (or takes poolId verbatim), derives the direction, and returns a QuoteResult — the quote plus the resolved poolId and xToY.
Pin a specific pool instead of resolving one from the symbol pair. The pool must still trade
exactly
from/to.A custodial wallet id you own — the quote then reports
walletBalanceIn and
sufficientBalance for that wallet. Requires an authenticated session context, so most SDK
callers omit it.NoDirectPoolError when no pool trades the pair (there is no multi-hop routing) and AmbiguousPoolPairError (with candidates) when several do — retry with poolId. The pool list backing symbol resolution is cached for 30 seconds per client instance.
Quotes made with your SDK key are settlement-accurate. Because the SDK sends your
x-sdk-key on every request, the backend prices your quotes with the same fee model
swaps.createSwap settles with: the live per-swap network fee is carved from the input
(networkFeeIn > 0, effInput = amount − networkFeeIn), so amountOut matches what
the swap actually returns (modulo price movement between quote and settlement). The response
reports this as feeModel: 'deposit'. Since the fee is roughly flat in USD per swap, it
dominates very small amounts — check networkFeeIn against amount before quoting tiny
swaps to users, and base minOut on this quote’s amountOut.pools.list
All pools available to the caller, with live reserves and fee configuration.
pools.get
One pool plus its full settled-swap history.
pools.getTicker
Live market data for a pool: USD price derived from the pool’s own reserve ratio, 24h change, and 24h volume. Returns a PoolTicker. Cached up to 30s server-side.
priceChange24h fields are null until the pool’s price history is at least 24h old, and price.usd is null for pools that cannot be USD-priced (e.g. unseeded pools).