Skip to content

CoinbaseProvider

Owns Coinbase withdraw selection state (token, network, funding tokens, dual crypto/fiat amount) and shared fetched data for the React hooks.

When to use

Wrap the Coinbase withdraw UI under SwappedConnectProvider. Selection hooks (useCoinbaseToken, useCoinbaseNetwork, useCoinbaseAmount, …) and startWithdrawal() require this provider.

Example

tsx
import { createSwappedConnectClient } from '@swapped/connect-sdk'
import {
  CoinbaseProvider,
  SwappedConnectProvider,
} from '@swapped/connect-sdk/react'

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

void client.loadSession()

function App() {
  return (
    <SwappedConnectProvider client={client}>
      <CoinbaseProvider>
        <WithdrawScreen />
      </CoinbaseProvider>
    </SwappedConnectProvider>
  )
}

Props

PropDefaultPurpose
enabledtrueSkip balance fetch when false
onlySupportedfalseFilter unsupported tokens from useCoinbaseBalances().balances
onlyAboveMinfalseFilter below-min balances from balances
defaultCurrencyPreferred initial token
defaultNetworkPreferred initial network
autoSelectTokentrueAuto-select the first eligible balance
autoSelectNetworktruetrue / false / 'only-one' — auto-select network always, never, or only when exactly one active network is available
resetAmountOnTokenChangefalseClear amount / touched when the token changes
maxAmountMode'balance'Which max ceiling blocks submit / Max — see below
clampToMaxfalseHard-clamp typed amounts to the blocking ceiling
maxDecimalsgetTokenDisplayDecimals(token) => number override for crypto amount input precision

Changing the selected token always clears the network selection.

When resetAmountOnTokenChange is false (default), the fiat amount is preserved across token changes and crypto is recomputed from the new token’s exchange rate. If the new token has no rate, crypto is kept and fiat is cleared. Set resetAmountOnTokenChange to true to clear both amounts instead.

Amount typing is capped to the token’s display decimals by default (USDC → 2, ETH → 6, …). Override per token:

tsx
<CoinbaseProvider maxDecimals={token => (token === 'ETH' ? 8 : 2)}>

maxAmountMode

There are two ceilings on a Coinbase withdrawal:

  • Hard — raw aggregated balance (above_balance)
  • Soft — balance minus the $1.50 fee reserve (above_spendable)
ModeMax buttonabove_spendableTypical use
'balance' (default)Sets raw balanceNon-blocking warning; submit auto-caps via onAmountAdjustedWidget-style flow
'spendable'Sets spendable maxBlocking errorStrict Max = spendable
tsx
{/* Widget flow (default) */}
<CoinbaseProvider>

{/* Strict spendable Max */}
<CoinbaseProvider maxAmountMode="spendable">

With clampToMax, typing above the blocking ceiling snaps on both sides (balance in 'balance' mode, spendable otherwise):

tsx
<CoinbaseProvider clampToMax>
HookRole
useCoinbaseBalancesBalance list data
useCoinbaseTokenSelected token
useCoinbaseFundingTokensFunding selection
useCoinbaseNetworkNetworks + selected network
useCoinbaseAmountDual crypto/fiat amount + limits
useCoinbaseSelectionFull selection snapshot
useCoinbaseWithdrawalstartWithdrawal() from context

Errors

CodeWhen
REACT_COINBASE_PROVIDER_REQUIREDA selection/data hook is used outside CoinbaseProvider

See Errors.