Appearance
@swapped/connect-sdk / core / Coinbase
Interface: Coinbase
Defined in: src/modules/coinbase/coinbase.module.ts:90
Coinbase connect and withdraw APIs.
Available on the client as client.coinbase. Event subscriptions and idle reads work before a session is loaded; connect / withdraw actions require loadSession().
Methods
cancelWithdrawal()
cancelWithdrawal():
void
Defined in: src/modules/coinbase/coinbase.module.ts:800
Cancel a withdrawal that is waiting for 2FA.
Clears the pending withdrawal so confirmWithdrawal can no longer be used for it. Does not cancel anything already submitted to Coinbase.
Returns
void
confirmWithdrawal()
confirmWithdrawal(
code):Promise<CoinbaseWithdrawalState>
Defined in: src/modules/coinbase/coinbase.module.ts:728
Confirm a pending withdrawal with a 2FA code.
Call this after startWithdrawal returns { status: 'requires2fa' }. Unlike starting a withdrawal, confirming is not blocked by the cooldown — the user can retry codes immediately if Coinbase rejects one.
A wrong code usually returns { status: 'requires2fa' } again (not thrown).
Parameters
code
string
Returns
Promise<CoinbaseWithdrawalState>
connect()
connect():
Promise<boolean>
Defined in: src/modules/coinbase/coinbase.module.ts:182
Open the Coinbase login flow. Returns true when connected.
Returns
Promise<boolean>
disconnect()
disconnect():
void
Defined in: src/modules/coinbase/coinbase.module.ts:197
Disconnect Coinbase and clear any in-progress withdrawal.
Returns
void
ensureSession()
ensureSession():
Promise<boolean>
Defined in: src/modules/coinbase/coinbase.module.ts:215
Check that the Coinbase session is still valid.
Returns false when the session expired; returns true on success or when a transient network error occurs.
Skips the network call when the local token is still within coinbase.tokenExpiryMs. Concurrent callers share one in-flight request. On success the local token (and timestamp) is updated. Transient errors fail open without touching the stored timestamp so the next call retries refresh ASAP.
Returns
Promise<boolean>
getActiveWithdrawal()
getActiveWithdrawal():
CoinbaseActiveWithdrawal|null
Defined in: src/modules/coinbase/coinbase.module.ts:810
Get the withdrawal currently waiting for 2FA, if any.
Present after startWithdrawal returns { status: 'requires2fa' } until the withdrawal completes, fails, or cancelWithdrawal is called.
Returns
CoinbaseActiveWithdrawal | null
getBalances()
getBalances(
__namedParameters?):Promise<CoinbaseBalance[]>
Defined in: src/modules/coinbase/coinbase.module.ts:286
Fetch enriched Coinbase account balances.
Parameters
__namedParameters?
forceRefetch?
boolean = false
Bypass RTK Query cache and hit the API again.
Returns
Promise<CoinbaseBalance[]>
getCompletedTransactionSummary()
getCompletedTransactionSummary():
CoinbaseCompletedTransactionSummary|null
Defined in: src/modules/coinbase/coinbase.module.ts:821
Display-ready summary of the last completed Coinbase withdrawal.
Built only from the in-memory withdraw API result. Returns null when there is no completed withdrawal for this session module (e.g. after reload or restartSession()).
Returns
CoinbaseCompletedTransactionSummary | null
getCooldown()
getCooldown():
CoinbaseCooldown
Defined in: src/modules/coinbase/coinbase.module.ts:842
Get the cooldown that prevents starting another withdrawal too quickly.
The timer starts when startWithdrawal is called (SDK default: 30s). While isInCooldown is true, startWithdrawal throws COINBASE_COOLDOWN_ACTIVE — use remainingMs (also pushed every second via onCooldownChanged) to show a wait UI. Confirming a 2FA code with confirmWithdrawal is not affected.
Returns
getDefaultFundingTokens()
getDefaultFundingTokens(
balances,destinationCurrency):TokenSymbol[]
Defined in: src/modules/coinbase/coinbase.module.ts:576
Default funding-token selection for a destination currency.
Parameters
balances
ExchangeBalanceItem[]
destinationCurrency
Returns
getFundingTokens()
getFundingTokens(
balances,destinationCurrency):CoinbaseFundingToken[]
Defined in: src/modules/coinbase/coinbase.module.ts:554
List funding tokens that can pay for a destination currency.
Parameters
balances
ExchangeBalanceItem[]
destinationCurrency
Returns
getMaxWithdrawableAmount()
getMaxWithdrawableAmount(
__namedParameters):number
Defined in: src/modules/coinbase/coinbase.module.ts:487
Max withdrawable amount after reserving the network fee (default $1.50). Use for Max button / amount-field caps — not for the displayed minimum. Pass symbol so the result is truncated down to display decimals (USDC → 2).
Parameters
__namedParameters
GetCoinbaseMaxWithdrawableAmountOptions
Returns
number
getMinWithdrawalAmount()
getMinWithdrawalAmount(
__namedParameters):Promise<number>
Defined in: src/modules/coinbase/coinbase.module.ts:457
Get the minimum withdrawal amount for a token.
Default (includeSwappedFee: false) is for the amount screen / network display: max(sessionWalletMin, balanceMin, max(Coinbase min, feeInCrypto)). Pass includeSwappedFee: true only for network-eligibility checks (adds the fee on top of Coinbase min).
Resolves exchange rate from balances when omitted.
Parameters
__namedParameters
GetCoinbaseMinWithdrawalAmountOptions
Returns
Promise<number>
getNetworks()
getNetworks(
__namedParameters):Promise<CoinbaseNetworkItem[]>
Defined in: src/modules/coinbase/coinbase.module.ts:350
Fetch available withdrawal networks for a currency (with per-network mins).
Parameters
__namedParameters
accountName
string
currency
Returns
Promise<CoinbaseNetworkItem[]>
getSelectionAggregatedBalance()
getSelectionAggregatedBalance(
__namedParameters):CoinbaseSelectionAggregatedBalance
Defined in: src/modules/coinbase/coinbase.module.ts:588
Aggregated balance for the selected destination and funding tokens.
Parameters
__namedParameters
balances
ExchangeBalanceItem[]
currency
fundingTokens?
Returns
CoinbaseSelectionAggregatedBalance
isConnected()
isConnected():
boolean
Defined in: src/modules/coinbase/coinbase.module.ts:162
Whether Coinbase is currently connected.
Returns
boolean
isInitializing()
isInitializing():
boolean
Defined in: src/modules/coinbase/coinbase.module.ts:167
Whether Coinbase is still initializing.
Returns
boolean
isPopupOpen()
isPopupOpen():
boolean
Defined in: src/modules/coinbase/coinbase.module.ts:177
Whether the Coinbase login popup is currently open.
Returns
boolean
onConnected()
onConnected(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:876
Subscribe when Coinbase connects.
Parameters
handler
(payload) => void
Returns
() => void
onCooldownChanged()
onCooldownChanged(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:923
Subscribe when the withdrawal-start cooldown changes.
Fired when cooldown begins (after startWithdrawal), every second while active (with updated remainingMs), and when it ends. Payload matches getCooldown.
Parameters
handler
(payload) => void
Returns
() => void
onDisconnected()
onDisconnected(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:883
Subscribe when Coinbase disconnects.
Parameters
handler
(payload) => void
Returns
() => void
onInitializationCompleted()
onInitializationCompleted(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:867
Subscribe when Coinbase finishes initializing.
Parameters
handler
(payload) => void
Returns
() => void
onInitializationStarted()
onInitializationStarted(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:858
Subscribe when Coinbase starts initializing.
Parameters
handler
(payload) => void
Returns
() => void
onOAuthError()
onOAuthError(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:947
Subscribe when the Coinbase login popup fails (blocked, closed, or auth error).
Parameters
handler
(payload) => void
Returns
() => void
onPopupOpenChanged()
onPopupOpenChanged(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:932
Subscribe when the Coinbase login popup opens or closes.
Parameters
handler
(payload) => void
Returns
() => void
onSessionEnsured()
onSessionEnsured(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:899
Subscribe when ensureSession() successfully validates / refreshes the token.
Parameters
handler
(payload) => void
Returns
() => void
onSessionExpired()
onSessionExpired(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:890
Subscribe when the Coinbase session expires.
Parameters
handler
(payload) => void
Returns
() => void
onWithdrawalCompleted()
onWithdrawalCompleted(
handler): () =>void
Defined in: src/modules/coinbase/coinbase.module.ts:908
Subscribe when a Coinbase withdrawal completes.
Parameters
handler
(payload) => void
Returns
() => void
ready()
ready():
Promise<void>
Defined in: src/modules/coinbase/coinbase.module.ts:172
Resolve when Coinbase has finished initializing.
Returns
Promise<void>
reset()
reset():
void
Defined in: src/modules/coinbase/coinbase.module.ts:960
Reset withdrawal and cooldown state. Connection status is unchanged.
Returns
void
startWithdrawal()
startWithdrawal(
request,options?):Promise<CoinbaseWithdrawalState>
Defined in: src/modules/coinbase/coinbase.module.ts:655
Start a Coinbase withdrawal.
Validates amount against min and fee-reserve max before calling the API. When the amount is above the fee-reserve max and the capped max is still viable, the amount is auto-adjusted and optional StartCoinbaseWithdrawalOptions.onAmountAdjusted is awaited. Return false from that callback to cancel — resolves { status: 'idle' } without starting cooldown. Other invalid amounts throw COINBASE_INVALID_WITHDRAWAL_AMOUNT. Prefer calling validateWithdrawalAmount in UI first for field errors.
Often returns { status: 'requires2fa' } — then call confirmWithdrawal with the user's 2FA code. Starting a withdrawal begins a short cooldown (see getCooldown); calling this again too soon throws COINBASE_COOLDOWN_ACTIVE.
Parameters
request
StartCoinbaseWithdrawalRequest
options?
StartCoinbaseWithdrawalOptions
Returns
Promise<CoinbaseWithdrawalState>
validateWithdrawalAmount()
validateWithdrawalAmount(
__namedParameters):Promise<CoinbaseWithdrawalAmountValidation>
Defined in: src/modules/coinbase/coinbase.module.ts:507
Validate amount against min and fee-reserve max before startWithdrawal. Does not throw on range errors — check ok.
Pass minAmount if already loaded, or symbol to fetch it. When resolving via symbol, pass network / balanceMin
Parameters
__namedParameters
ValidateCoinbaseWithdrawalAmountOptions
Returns
Promise<CoinbaseWithdrawalAmountValidation>