Skip to content

Limits

Compute min / max withdrawal amounts and validate for field-level UX.

When to use

On the amount form, after balances, optional funding tokens, and networks. Use these helpers to drive the amount field (min hint, Max button, inline errors). startWithdrawal still validates against fresh balances and auto-adjusts above-spendable amounts to the fee-reserve max (see withdrawal); validateWithdrawalAmount is for UI feedback only.

Methods

MethodPurpose
getMinWithdrawalAmount({ symbol, exchangeRate?, network?, … })Minimum crypto amount for the field
getMaxWithdrawableAmount({ balance, exchangeRate?, symbol? })Max after fee reserve (Max button); pass symbol to truncate down to display decimals (USDC → 2)
validateWithdrawalAmount({ amount, balance, … }){ ok: true, … } or { ok: false, reason } — does not throw for range errors

reason when invalid: invalid_amount | below_min | above_spendable.

Example

ts
import { TokenSymbol } from '@swapped/connect-sdk';

const minAmount = await client.coinbase.getMinWithdrawalAmount({
  symbol: TokenSymbol.USDC,
  exchangeRate: usdc.exchangeRate,
  network: network?.id,
});

const maxAmount = client.coinbase.getMaxWithdrawableAmount({
  balance: selection.balance,
  exchangeRate: usdc.exchangeRate,
  symbol: TokenSymbol.USDC,
});

const validation = await client.coinbase.validateWithdrawalAmount({
  amount: userInput,
  balance: selection.balance,
  exchangeRate: usdc.exchangeRate,
  symbol: TokenSymbol.USDC,
  network: network?.id,
});

if (!validation.ok) {
  // Show validation.reason on the amount field.
  // above_spendable is also auto-adjusted by startWithdrawal if the capped max is viable.
}

Errors

CodeWhenWhat to do
COINBASE_INVALID_WITHDRAWAL_AMOUNTstartWithdrawal with below-min / invalid amount, or above-spendable with no viable capFix the field; see withdrawal for auto-adjust
UNKNOWN_ERRORvalidateWithdrawalAmount called without minAmount or symbolPass one of them
COINBASE_NOT_CONNECTED / COINBASE_SESSION_EXPIREDMin fetch needs API / JWTConnect first

See Errors.