Skip to content

useCoinbaseNetwork

Load withdrawal networks for the selected Coinbase currency and manage the selected network.

When to use

Inside CoinbaseProvider, after the user picks a token (and optional funding). Prefer eligible networks for the amount form.

Example

tsx
import { useCoinbaseNetwork } from '@swapped/connect-sdk/react'

function NetworkPicker() {
  const {
    activeNetworks,
    selectedNetwork,
    select,
    isLoading,
    error,
  } = useCoinbaseNetwork()

  if (isLoading) return <p>Loading networks…</p>
  if (error) return <p>{error.message}</p>

  return (
    <ul>
      {activeNetworks.map(network => (
        <li key={network.id}>
          <button
            type="button"
            disabled={!network.eligible}
            aria-pressed={selectedNetwork === network.id}
            onClick={() => select(network.id)}
          >
            {network.name}
            {!network.eligible ? ` (${network.ineligibleReason})` : ''}
          </button>
        </li>
      ))}
    </ul>
  )
}

ineligibleReason: inactive | insufficient_balance.

Returns

FieldPurpose
networks / activeNetworks / eligibleNetworksLists
selectedNetwork / selectedNetworkItemSelection
select / clearUpdate selection
isLoading / isRefetching / error / refetchFetch state

Requires CoinbaseProvider. Account id, currency, and available balance are taken from the current selection.

Errors

CodeWhenWhat to do
REACT_COINBASE_PROVIDER_REQUIREDOutside providerWrap with CoinbaseProvider
COINBASE_NOT_CONNECTEDNot connectedConnect first
COINBASE_SESSION_EXPIREDToken invalidReconnect
API_ERRORNetwork / server failureRetry

See Errors.