Appearance
For AI agents
This page is a condensed reference for coding agents (Claude Code, Cursor, Codex, etc.) integrating @swapped/connect-sdk. It duplicates nothing you can't also get from the guide - it just puts the load-bearing facts in one place.
Prefer fetching content directly over browsing:
/llms.txt- link index of every page on this site, one line each/llms-full.txt- the entire site concatenated into one file- Any page as raw Markdown: append
.mdto its URL, e.g./guide/core/getting-started.md - Every rendered page also has Copy page / View as Markdown buttons under its title
What this SDK does
Framework-agnostic client for Swapped Connect: deposits via self-custodial wallets, exchange apps (Exchange Pay), Cash App, or Coinbase OAuth - driven by a sessionId your backend creates. No hosted widget UI. By default the SDK mounts a hidden {widgetBaseUrl}/gateway iframe (wallets / coinbase). Pass modules: ['exchangePay'] (and/or cashApp) to skip it.
Two entry points, same underlying client:
| Import | Track |
|---|---|
@swapped/connect-sdk | Core - framework-agnostic. React is an optional peer and is not installed unless you use it. |
@swapped/connect-sdk/react | React - provider + hooks on top of a core client. Requires react >= 18. |
@swapped/connect-sdk/format | Display/formatting helpers, both tracks |
@swapped/connect-sdk/wallet-verification | Standalone address verification. Not checkout. |
@swapped/connect-sdk/wallet-verification/react | Provider + hooks for wallet verification. |
Non-obvious constraints
- This SDK is browser only. Do not create a client or call SDK methods on the server (Node.js, SSR, RSC).
createSwappedConnectClientthrowsBROWSER_REQUIREDoutside the browser. In Next.js, use a client component ('use client') or a client-only module. - CSP: unless
modulesomits bothwalletsandcoinbase, the SDK mounts a hidden iframe at{widgetBaseUrl}/gatewayand opens a WebSocket to{apiBaseUrl}/swapped-connect. If the merchant site sends a Content-Security-Policy, allow those origins - see Browser requirements.WALLET_GATEWAY_NOT_READYusually meansframe-srcblocked the iframe;WEBSOCKET_CONNECTION_FAILEDusually meansconnect-srcblockedwss:. modules: omit to enableexchangePay,cashApp,coinbase, andwallets. A listed subset constructs only those modules (MODULE_NOT_ENABLEDif you call one that was left out) and hides the other methods frompaymentMethods.get()/useGetPaymentMethods().- The
sessionIdmust come from your backend. It's an HMAC-signed request that requires a secret key - never sign it in the browser. See Creating a session. Pair the session host with the client:environment: 'staging'(sessionPOST https://staging-api.swapped.app/api/sessions) or production (default,POST https://connect-api.swapped.com/api/sessions). A staging session does not load against production - andgetSessionView()/useSessionView()still reportactivewhen no session is loaded. - Optional
apiBaseUrl/widgetBaseUrloverride that environment's defaults.apiBaseUrlis allow-listed to the official production and staging API hosts. - Only
activesessions can pay. Gate any payment UI on the session view (getSessionView()/useSessionView()), not rawSessionData.session.status. Calling a payment method while inactive throwsSESSION_NOT_ACTIVE. - Call
loadSession()once, before rendering payment UI. In React, the provider does not load the session for you - do it once at bootstrap, outside the component tree. A second call uses the cache unless you pass{ forceRefetch: true }. You almost never need that - sockets and payment completion already refresh the session. restartSession()before starting another payment after completion/expiry/failure - don't create a new client.- Wallets (self-custodial connect), Exchange Pay (exchange-app QR/checkout), Cash App (Cash App / Lightning), and Coinbase (OAuth) are four distinct flows - see Concepts before assuming one covers the others.
- Wallet verification is a separate product. Import
createWalletVerificationfrom@swapped/connect-sdk/wallet-verification, orWalletVerificationProviderfrom@swapped/connect-sdk/wallet-verification/react. It takes a publicapiKey, not asessionId. Do not reuse Connectclient.walletsorclient.coinbase. See Wallet verification.
Minimal working example (Core)
ts
import { createSwappedConnectClient } from '@swapped/connect-sdk'
const client = createSwappedConnectClient({
sessionId: 'your-session-id',
environment: 'staging', // omit or 'production' for live
})
await client.loadSession()
const view = client.getSessionView()
if (view.type === 'active') {
const methods = await client.paymentMethods.get({ category: 'wallets' })
// route into Wallets / Exchange Pay / Cash App / Coinbase based on `methods`
}Minimal working example (React)
tsx
import { createSwappedConnectClient } from '@swapped/connect-sdk'
import {
SwappedConnectProvider,
useGetPaymentMethods,
} from '@swapped/connect-sdk/react'
const client = createSwappedConnectClient({
sessionId: 'your-session-id',
environment: 'staging', // omit or 'production' for live
})
void client.loadSession() // outside the tree, once
function App() {
return (
<SwappedConnectProvider client={client}>
<PaymentMethods />
</SwappedConnectProvider>
)
}
function PaymentMethods() {
const { paymentMethods, isLoading } = useGetPaymentMethods({
category: 'exchanges',
})
if (isLoading) return <p>Loading…</p>
return (
<ul>
{paymentMethods.map(m => (
<li key={m.id}>{m.name}</li>
))}
</ul>
)
}Integration order
- Backend: sign and create a session → Creating a session
createSwappedConnectClient→loadSession()- Gate UI on session view - Core / React
- List payment methods - Core / React
- Implement one deposit flow - Wallets, Exchange Pay, Cash App, or Coinbase (each has a React equivalent under
/guide/react/) - Handle events and errors per-module
restartSession()for another payment,destroy()on teardown
Wallet verification (standalone)
Not a Connect session. Prove the user controls customerId + address (reuse key - already verified returns verified immediately).
ts
import { createWalletVerification } from '@swapped/connect-sdk/wallet-verification'
const client = createWalletVerification({
apiKey: 'your-public-api-key',
environment: 'staging',
})
const prepared = await client.wallets.prepareVerify({
network: 'evm',
customerId: 'user-1234',
provider: wallets[0].provider,
address: '0xAb58…',
onUri: ({ uri, deeplinkUrl }) => { /* WalletConnect QR */ },
onDeeplinkUrl: ({ url }) => { /* browse QR */ },
})
const verification = await prepared.wait()
// or client.wallets.verify({ prepared, transport: 'injected', ... })
// Coinbase: startVerification() then openVerificationTab() from a click
// Same-tab: startVerification({ mode: 'redirect', redirectUrl }) then completeVerification() on the landing page- Signature:
client.wallets.verify()one-shot, orprepareVerify()thenverify({ prepared })/verify({ verificationId }).prepareVerifyneedsaddress. Abort a prepare withprepared.cancel(). - Coinbase:
client.coinbase. New-tab default;redirectrequiresredirectUrl. - Statuses:
pending(retry this step),verified(done),failed/expired(new verify). Invalid signature stayspending. - One verification at a time (
WALLET_VERIFICATION_IN_PROGRESS).destroy()on teardown. - Guide: Wallet verification (Core) / React
Full references
- Getting started (Core) / Getting started (React)
- Client (Core) / Client (React) - config, modules, lifecycle
- Wallet verification / React - standalone address proof
- Browser requirements - CSP, hidden gateway iframe, WebSocket
- Concepts - glossary and session lifecycle
- API reference - generated from source types