Skip to main content

Install

npm install @oneswap/sdk

Initialize

import { OneSwap } from '@oneswap/sdk'

const client = new OneSwap({
  apiKey: 'os_live_...',
  timeout: 30000 // optional, milliseconds
})
Get your API key from oneswap.cc.

Get a quote

const quote = await client.quotes.get({
  from: 'Amulet',
  to: 'USDCx',
  amount: '100'
})

console.log(`Rate: 1 Amulet = ${quote.rate} USDCx`)
console.log(`Output: ${quote.outputAmount} USDCx`)
console.log(`Price impact: ${quote.priceImpact}%`)

Create a swap

const intent = await client.swaps.create({
  fromToken: 'Amulet',
  toToken: 'USDCx',
  amount: '100',
  slippageTolerance: 0.01 // 1%
})

console.log(`Deposit ${intent.expectedAmount} Amulet to: ${intent.depositAddress}`)

Wait for completion

// Event-based
intent.on('matched', () => console.log('Deposit detected'))
intent.on('completed', (status) => console.log(`Got ${status.actualOutput} USDCx`))

// Or await
const result = await intent.wait()
console.log(`Swap complete: ${result.actualOutput} ${result.outputToken}`)

Custodial wallets

Create managed wallets so your users don’t need their own Canton party:
const wallet = await client.wallets.create({ userId: 'user-123' })

const intent = await client.swaps.create({
  fromToken: 'Amulet',
  toToken: 'USDCx',
  amount: '100',
  userId: 'user-123' // uses custodial wallet address
})

Next steps