Skip to content

Wallets (React)

Connect self-custodial wallets and deposit using hooks from @swapped/connect-sdk/react.

Wallets is a separate flow from Exchange Pay and Coinbase OAuth. Route to it when the payment method has type: wallet (see Payment methods).

Prerequisites

  1. Create a core client with a Swapped Connect sessionId (from your backend).
  2. Call loadSession() and wrap your tree with SwappedConnectProvider.
  3. Wrap wallet UI with WalletsProvider.
tsx
import { createSwappedConnectClient } from '@swapped/connect-sdk'
import {
  SwappedConnectProvider,
  WalletsProvider,
} from '@swapped/connect-sdk/react'

const client = createSwappedConnectClient({
  sessionId: 'your-session-id',
})

void client.loadSession()

function App() {
  return (
    <SwappedConnectProvider client={client}>
      <WalletsProvider>
        <WalletsFlow />
      </WalletsProvider>
    </SwappedConnectProvider>
  )
}

Available wallet → connect → walletIdtransfer plansubmit

Flow overview

StepWhat happensHook
1. AvailabilityWallet payment methods + transports on this deviceuseAvailableWallets
2. ConnectExtension, WalletConnect, or open-in-wallet-appConnect wallet / useWallet
3. ConnectionsConnected instances + active walletConnected wallets / useActiveWallet
4. BalancesTokens (crypto + fiat)useWalletBalances
5. Transfer planHow this token reaches the session (direct / swap / bridge / unavailable)Transfer plan
6. Amount + quoteDual crypto/fiat input, min, quoteAmount & quote
7. SubmitConfirm in wallet; status; requires_retrySubmit (useWalletTransfer)
8. DoneSummary; restartSession()useWalletCompletedTransactionSummary

Session must be loaded and active before submit. After a completed payment, call restartSession() before starting another one. Connected wallets persist across restartSession().

WalletsProvider tracks the active wallet and persists it in localStorage (survives refresh). A successful connect selects that instance; if the active wallet disconnects, the newest remaining connection is selected. Keep the selected token (and amount) in your own state.

usePrepareWalletTransfer({ enabled }) optionally warms swap/bridge currency lists when entering a wallets screen.

TermMeaning
Available walletA payment-method wallet this device can connect. useAvailableWallets
ConnectionOne approved instance (walletId). Same brand can appear more than once. useWalletConnections
Active walletThe selected walletId for UI. useActiveWallet
Transfer planHow a token reaches the session (direct / swap / bridge / unavailable). Transfer plan

Walkthrough: Example.

Hooks

Full list: Wallets hooks. Use state hooks for UI and event hooks for side effects.

useAvailableWallets, useConnectWallet, useWallet, useWalletConnections, useActiveWallet, and the balance hooks require WalletsProvider. Transfer plan / quote / submit / summary hooks work under SwappedConnectProvider alone — but you still need a connected walletId. WalletsProvider is what tracks the active wallet and the connection list.