@silentswap/sdk
v2.3.0
Published
One RFQ-style TypeScript client for private SilentSwap orders and Simple Bridge.
Keywords
Readme
@silentswap/sdk
One RFQ-style TypeScript client for private SilentSwap orders and Simple Bridge.
Install
pnpm add @silentswap/sdk viemviem is a peer dependency.
Quick start
import { createSilentSwapClient, parseUsdc } from '@silentswap/sdk';
import { createWalletClient, custom } from 'viem';
import { mainnet } from 'viem/chains';
const transport = custom(window.ethereum);
const discoveryClient = createWalletClient({ chain: mainnet, transport });
const [account] = await discoveryClient.getAddresses();
const walletClient = createWalletClient({ account, chain: mainnet, transport });
const client = createSilentSwapClient({
walletClient,
// Registered integrations receive this from SilentSwap.
// integratorId: 'int_0123456789abcdef01234567',
});
const quote = await client.quote({
privacy: true,
inputAddress: account,
sourceChainId: 1,
sourceAsset: 'USDC',
outputs: [
{
address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
chainId: 8453,
amount: parseUsdc('100'),
},
],
});
// Display every output, fee, and the expiration before this call.
const order = await client.placeOrder(quote);
const stop = client.trackOrderViaWebSocket(order.reference, console.log, console.error);Amounts
Private API USDC fields use the gateway chain's USDC precision. Never hardcode a decimals
literal: use parseUsdc for requests, formatUsdc for responses, and USDC_DECIMALS when a
numeric precision is required. Amount-range error bodies also include usdcDecimals.
Production defaults to https://api.silentswap.com. Set baseUrl only for tests or a
self-hosted API. Browser applications must register their exact HTTPS production origin with
SilentSwap support; server-side clients are unaffected by browser CORS. Registered integrators
configure the issued integratorId on the client. Total fee, integrator/SilentSwap split, and
payout address are controlled by SilentSwap and cannot be supplied per quote. Browser testing is enabled by default on
http://localhost:3000 and http://127.0.0.1:3000; see
testing and production access.
Main API
| Method | Purpose |
| --- | --- |
| quote(request) | Quote a private route (privacy: true) or Simple Bridge (privacy: false). |
| placeOrder(quote) | Approve when needed and submit the wallet transaction, or return pay-in instructions. |
| trackOrderViaWebSocket(reference, onState, onError?) | Track private SSE/polling or Simple Bridge polling through one status model. |
| executeRefund(privateReference) | Refund an eligible expired private EVM-origin order. |
Non-EVM wallets are supplied through narrow capability adapters. The SDK never discovers injected wallets or chooses a wallet brand. Existing V2 orders must finish with the pinned 0.x SDK before an integration cuts over to 2.0.
See the documentation and V2 migration guide.
Private order access
Requires @silentswap/sdk 2.2.0 or later. A ticket is public on-chain and is
not a read credential. Fresh private quotes include an accessToken; the SDK
remembers it and carries it in the returned PrivateOrderReference. Keep the
reference private and persist it securely if tracking must survive a reload, or
provide orderAccessTokenStore in the SDK configuration. The application can
track with that credential without another wallet signature.
Direct HTTP integrations must send Authorization: Bearer <accessToken> to
GET /order/:ticket, GET /order/:ticket/events, and
POST /order/:ticket/deposit-tx. Never put the token in a URL, log, analytics
payload, public link or transaction calldata. Browser SSE uses fetch so this
header can be sent; native EventSource cannot send it.
A missing or wrong credential returns HTTP 401 with order_access_required. For
legacy orders, an authenticated Activity session belonging to the recorded EVM
signer can recover access. A public ticket or a claimed sender address is
insufficient. Old orders created with an ephemeral signer and no saved
credential cannot recover tracking this way; this does not change processing or
on-chain refund rights. Existing integrations must upgrade to 2.2.0+ or send the
header from their HTTP calls.
The credential authorizes that order's reads and deposit-hash notification; it cannot sign or spend funds. It persists across wallet disconnects and expires on server secret rotation, not Activity sign-out. Treat a saved reference as private browser/app data. Clearing saved data loses access unless owner recovery is available.
License
MIT
