swaps (execution), quotes, pools, and tokens (market data).
Constructor
string
required
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.'mainnet' | 'devnet'
default:"mainnet"
Which OneSwap backend to use. The SDK resolves the URL itself — you never pass a raw URL.
number
default:"30000"
Per-request timeout in milliseconds.
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.string
required
Your stable id for the end-user. Only one open swap per
userRef at a time.string
required
The token the user deposits, e.g.
'CBTC'.number
required
Decimal amount of
inSymbol to swap. The deposit must arrive within 1% of this amount.string
required
The token to return to the user, e.g.
'HTEST'.string
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.number
Optional hard floor on the output amount. If the swap would return less than this, it is refunded.
number
default:"200"
Optional slippage tolerance in basis points. Defaults to
200 (2%).{ 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.
string
required
The swap id returned by
createSwap (esc_...).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.
string
required
The swap id to wait on.
number
default:"3000"
Poll interval in milliseconds.
number
default:"900000"
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.
string
required
Your stable identifier for the end user, the same value passed to
createSwap.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.
string
required
The swap id to cancel (
esc_...).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.
string
required
Symbol of the token you pay with, e.g.
'CC'.string
required
Symbol of the token you receive, e.g.
'CBTC'.number
required
Amount of
from to swap. Must be positive.string
Pin a specific pool instead of resolving one from the symbol pair. The pool must still trade
exactly
from/to.string
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.
string
required
The pool id (
rt-...), from pools.list() or a quote’s poolId.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.
string
required
The pool id (
rt-...).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).