TypeScript SDK
The @swapper-finance/deposit-sdk package includes SwapperApiClient, a typed client for API v1: chains and tokens, quotes ready to sign, transfer status, and deposit addresses — with retries, timeouts, rate-limit headers and typed errors handled for you.
Zero runtime dependencies. It uses the global
fetch(Node.js 18+, browsers, Deno, Bun, edge runtimes).Typed from the API contract. Every request and response is typed (
Step,Estimate,FeeCost,StatusResponse, …).Wallet-agnostic. It never signs: send the returned
transactionRequestwith viem, ethers, a Solana wallet, or a custodial API.
npm install @swapper-finance/deposit-sdkSwapperApiClient is included from version 0.5.0 of the package.
Create a client
import { SwapperApiClient } from "@swapper-finance/deposit-sdk";
// On your server, with an API key
const swapper = new SwapperApiClient({ apiKey: process.env.SWAPPER_API_KEY });
// Or on the free tier (server or browser), with your integratorId
const swapper = new SwapperApiClient({ integrator: "YOUR_INTEGRATOR_ID" });integrator
—
Your integratorId, sent with every request when there is no apiKey. Required for quotes on the free tier.
baseUrl
https://swapper.finance/api/v1
API base URL.
timeoutMs
30000
Timeout of each attempt, in milliseconds.
maxRetries
2
Automatic retries on 429, 5xx, network errors and timeouts. 0 disables them.
With an
apiKey, the client does not sendintegratorunless you pass it togetQuoteexplicitly — the key already identifies you, and anintegratorthat doesn't match it fails withINVALID_INTEGRATOR.Without a key,
integratoris sent on every request: it's required on quotes, and on the other endpoints it counts the call under your integrator on the dashboard's API usage page.
Quick start
Quote 10 USDC on Base into ETH on Arbitrum, approve if needed, send, and track the transfer:
A typical setup keeps the key on your backend: the backend calls getQuote and returns quote.transactionRequest to your frontend, the user's wallet signs and sends it, your frontend reports the transaction hash, and the backend tracks it with waitForStatus.
Sending with viem
transactionRequest holds plain strings, so it maps onto any wallet library. With viem (not a dependency of the SDK):
With ethers v6, pass the fields straight through: signer.sendTransaction({ to: tx.to, data: tx.data, value: tx.value, gasLimit: tx.gasLimit }). On Solana, transactionRequest.data is a base64-encoded VersionedTransaction to sign and send, and no approval is needed. See Quote → Executing a quote.
Methods
Each method returns the response body of its endpoint, and takes an optional last argument { signal?: AbortSignal, requestId?: string }. Chains (ChainIdOrKey = string | number) can be given by Swapper chain id or key — "8453", "mainnet-beta", "base", "solana" — and EVM ids also as numbers (8453). Responses always carry the chain id, as a string.
getQuote({ fromChain, toChain, fromToken, toToken, fromAmount, fromAddress, toAddress?, slippage?, fee?, integrator? })
Step (alias Quote)
waitForStatus(params, options?)
polls GET /v1/status
StatusResponse (final)
createDepositAddress({ fromChain, fromToken, toChain, toToken, toAddress, refundAddress? })
POST /v1/deposit-address (API key)
DepositAddress
getDepositAddressStatus({ address })
{ address, transfers: StatusResponse[] }
fromAmount takes a string or a bigint. slippage and fee are decimal fractions (0.005 = 0.5%); feeFromBps(30) gives 0.003. ecosystems is an array of Ecosystem ("evm", "solana"):
Deposit addresses
createDepositAddress needs the client's apiKey. The same parameters always return the same address, so it's safe to call again (and is retried like a read). Checking the status is what records new deposits and sends their webhook — see Deposit Addresses → Polling.
Tracking with waitForStatus
waitForStatus polls until the transfer is DONE or FAILED and resolves with that status — check substatus, since DONE can also be REFUNDED. Along the way it:
keeps polling through
NOT_FOUNDfor up tonotFoundTimeoutMs(10 minutes by default) — normal right after broadcasting — then rejects withTRANSFER_NOT_FOUND;keeps polling through
429(waiting at leastRetry-After),5xxand network errors;throws any other error at once, rejects with
TIMEOUTaftertimeoutMs, and stops withABORTEDwhen itssignalfires.
Errors
Every failure is a SwapperApiError:
code
The API's error code (INVALID_FEE, NO_ROUTE_FOUND, …), or a client code below. Branch on it.
status
HTTP status; 0 when no response was received.
requestId
The request's X-Request-Id. Always set — the client sends its own id, so even timeouts have one. Include it when you contact support.
retryAfter
Seconds to wait, from Retry-After (on 429).
rateLimit
The failed response's X-RateLimit-* headers, when present.
retryable
true for 429, 5xx, network errors and timeouts.
Codes set by the client itself:
NETWORK_ERROR
No response (DNS failure, connection refused or reset).
TIMEOUT
No response within timeoutMs, or waitForStatus reached its own timeoutMs.
ABORTED
Your AbortSignal fired.
INVALID_RESPONSE
The body wasn't the API's JSON (e.g. a proxy's HTML error page); status is the HTTP status.
TRANSFER_NOT_FOUND
waitForStatus still got NOT_FOUND after notFoundTimeoutMs.
Retries and rate limits
Retries.
429,5xx, network errors and timeouts are retried up tomaxRetriestimes with exponential backoff and jitter. A429is retried afterRetry-After(up to 60 seconds; a longer wait is left to you). Other4xxerrors are never retried, as recommended in Errors.Rate-limit headers.
swapper.lastRateLimitholds theX-RateLimit-*headers of the most recent response that carried them —{ limit, remaining, reset }, withresetin unix seconds — orundefinedbefore the first one.
Helpers
NATIVE_TOKEN_ADDRESS
0x0000000000000000000000000000000000000000, the native token on EVM chains.
approvalNeeded(quote)
true when the quote's source token is an ERC-20 that must be approved for estimate.approvalAddress; false for native tokens and Solana. It doesn't read the chain — compare the current allowance before approving.
feeFromBps(bps)
Whole basis points → the fee fraction: feeFromBps(30) === 0.003. Throws for fractional or negative values.
All request and response types are exported too: Chain, Token, Step / Quote, Action, Estimate, FeeCost, GasCost, TransactionRequest, StatusResponse, TransactionInfo, ErrorCode, RateLimitInfo, and the request types QuoteRequest, GetStatusRequest, TokensRequest, …, ChainIdOrKey and Ecosystem.
Last updated