Skip to main content
This walks you through one complete swap: quote it, create it, hand your user a deposit party, and wait for the output to be returned to them.
1

Install the SDK

2

Create an API key

Create an SDK key from your OneSwap account (self-serve) — swap.oneswap.cc for mainnet, devnet.oneswap.cc for devnet. The key looks like sk_live_ followed by 48 hex characters and is shown once at creation — store it somewhere safe. See API keys for the full flow.Keep the key on your server only. It is your integrator credential; never ship it to a browser or to an end-user.
3

Initialize the client

The client sends your key on every request as the x-sdk-key header. It talks to mainnet by default; pass environment: 'devnet' to use the devnet backend — the SDK resolves the URL itself, so you never set one:
4

Quote the swap

Before creating anything, ask what the swap would return. The SDK finds the pool that trades the pair and derives the direction for you:
If no pool trades the pair directly, this throws NoDirectPoolError — route through an intermediate asset (usually CC) as two separate swaps.
5

Create the swap

Only one open swap is allowed per userRef at a time.
6

Show the user the deposit party

Tell your end-user to send amountIn of inSymbol (here, 0.01 CBTC) to swap.depositParty before swap.deadline (60 minutes from creation).The deposit must land within 1% of amountIn, or it is refunded. OneSwap never guesses intent from a wrong amount.
7

Wait for completion

waitForSwap resolves once the swap reaches a terminal status (returned, refunded, expired, or failed), or when its local timeout is hit.

Complete example

Reading the market

The same client reads pools, tickers, and tokens — useful for building your own token pickers and price displays:
priceChange24h fields are null while the price history is warming up (the first 24h after a pool starts being tracked).

What’s next

Swaps guide

Lifecycle, tolerances, min-out, and reconciliation

API keys

Create, rotate, and revoke keys safely

Error handling

Typed errors, refunds, expiries, and robust polling

SDK methods

The full client surface