Appearance
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
| Method | Purpose |
|---|---|
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
| Code | When | What to do |
|---|---|---|
COINBASE_INVALID_WITHDRAWAL_AMOUNT | startWithdrawal with below-min / invalid amount, or above-spendable with no viable cap | Fix the field; see withdrawal for auto-adjust |
UNKNOWN_ERROR | validateWithdrawalAmount called without minAmount or symbol | Pass one of them |
COINBASE_NOT_CONNECTED / COINBASE_SESSION_EXPIRED | Min fetch needs API / JWT | Connect first |
See Errors.