Orkid

SDK reference

TypeScript SDK for the Orkid Swap API.

The @orkid/sdk package provides a typed client, Permit2 signing helpers, and a CLI for the Orkid Swap API.

Install

npm install @orkid/sdk

Peer dependencies (only needed for signing):

npm install viem
# or
npm install ethers

Exports

ExportDescription
OrkidClientMain API client — getQuote, solve, confirmTransaction, getAccount, getUsage, getRebates
SANDBOX_BASE_URL'https://sandbox.orkidlabs.com' — pass as baseUrl for the sandbox
OrkidPermitSignerPermit2 signing helper (viem and ethers variants)
ORKID_CHAIN_CONFIGPer-chain metadata (TVMExecutor, Permit2, RPC, explorer, min notional)
PERMIT2Canonical Permit2 address: 0x000000000022D473030F116dDEE9F6B43aC78BA3

Quick start — production

import { OrkidClient, OrkidPermitSigner } from '@orkid/sdk'
import { createWalletClient, http } from 'viem'
import { base } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'

const client = new OrkidClient({
  apiKey: process.env.ORKID_API_KEY!,
  // baseUrl defaults to https://orkidlabs.xyz
})

const account = privateKeyToAccount('0x...')
const walletClient = createWalletClient({ account, chain: base, transport: http() })
const permitSigner = new OrkidPermitSigner(walletClient)

async function swapUsdcToWeth() {
  const quote = await client.getQuote({
    from: 'USDC',
    to: 'WETH',
    amount: '25.0',
    chain: 'base',
  })

  if (!quote.ok) throw new Error(quote.error)

  const signed = await permitSigner.prepareAndSign({
    fromToken: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
    fromDecimals: 6,
    amount: '25.0',
    chain: 'base',
  })

  const result = await client.solve({
    from: 'USDC',
    to: 'WETH',
    amount: '25.0',
    chain: 'base',
    user: account.address,
    fromAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
    fromDecimals: 6,
    toAddress: '0x4200000000000000000000000000000000000006',
    toDecimals: 18,
    dryRun: false,
    permit: signed.permit,
    signature: signed.signature,
  })

  if (!result.ok) throw new Error(result.error)
  console.log('txHash', result.transaction?.txHash)
}

Quick start — sandbox

import { OrkidClient, OrkidPermitSigner, SANDBOX_BASE_URL } from '@orkid/sdk'

const sandbox = new OrkidClient({
  apiKey: process.env.ORKID_SANDBOX_KEY!,
  baseUrl: SANDBOX_BASE_URL, // https://sandbox.orkidlabs.com
})

// Same API surface — quotes are real, solves are always dry-run
const quote = await sandbox.getQuote({
  from: 'USDC',
  to: 'WETH',
  amount: '25.0',
  chain: 'arbitrum',
})

OrkidClient methods

MethodDescription
getQuote(params)Call /api/v1/route
solve(params)Call /api/v1/solve
confirmTransaction(txHash, chain)Call /api/v1/confirm for user-pays-gas swaps
getAccount()Call /api/v1/account
getUsage(params)Call /api/v1/usage
getRebates(params)Call /api/v1/rebates
getTokens(chain, search)Search tokens on a chain

OrkidPermitSigner

The OrkidPermitSigner handles nonce discovery, Permit2 typed data construction, and signing.

const signed = await permitSigner.prepareAndSign({
  fromToken: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
  fromDecimals: 6,
  amount: '25.0',
  chain: 'base',
})

// signed.permit — the PermitTransferFrom data (without spender)
// signed.signature — 65-byte hex signature

See the Permit2 signing walkthrough for the manual flow.

Examples

See the examples/ directory in the SDK package for complete, runnable examples:

  • examples/vanilla-viem.ts — full flow with a viem wallet client
  • examples/vanilla-ethers.ts — full flow with an ethers signer
  • examples/react.tsx — React hook wrapper
  • examples/nextjs-server-action.ts — server-side key protection in a Next.js app
  • examples/curl.sh — copy-paste curl commands

On this page