Skip to content

Getting started (Core) ​

Use the framework-agnostic client from @swapped/connect-sdk.

This SDK is browser only. Do not create a client or call SDK methods on the server (Node.js, SSR, RSC). createSwappedConnectClient throws BROWSER_REQUIRED if it is initialized outside the browser. Session creation stays on your backend - see Creating a session. If your site sends a Content-Security-Policy, allow the Swapped widget and API origins - see Browser requirements.

Install ​

bash
npm install @swapped/connect-sdk

React is not required. Install it only if you use the React track.

Create client and load session ​

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 session = client.getSession()
console.log(session?.merchant.name)

You need a Swapped Connect sessionId from your backend before creating the client - see Creating a session. Create that session against the same environment the client uses.

Config (environment, modules, apiBaseUrl, widgetBaseUrl), lifecycle (loadSession, restartSession, destroy), and client errors: Client.

Typical order of work ​

  1. createSwappedConnectClient → loadSession - Client
  2. Gate UI on session view (getSessionView) - only active can pay
  3. List payment methods
  4. Run a deposit flow - Wallets, Exchange Pay, Cash App, or Coinbase
  5. Listen for events as needed
  6. restartSession() for another payment, or destroy() when done

Entry points ​

ImportPurpose
@swapped/connect-sdkClient, types, modules
@swapped/connect-sdk/localesLanguage
@swapped/connect-sdk/formatDisplay helpers
@swapped/connect-sdk/wallet-verificationStandalone wallet verification

Address ownership (not checkout) is a separate import: Wallet verification.

Prefer React? See the React track.