Skip to content

Funding tokens

Combine other Coinbase balances into the selected withdrawal currency (local aggregation helpers).

When to use

After balances, when the user can optionally fund the withdraw with other tokens (for example ETH → USDC). Pass the selected symbols into startWithdrawal.

Methods

MethodPurpose
getFundingTokens(balances, destinationCurrency)Candidates that can fund the destination
getDefaultFundingTokens(balances, destinationCurrency)Default selected set
getSelectionAggregatedBalance({ balances, currency, fundingTokens })Combined balance / USD for min-max

Pass balance.raw from getBalances() into these helpers.

Example

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

const balances = await client.coinbase.getBalances();
const raw = balances.map(item => item.raw);

const fundingTokens = client.coinbase.getFundingTokens(
  raw,
  TokenSymbol.USDC,
);

const selected = client.coinbase.getDefaultFundingTokens(
  raw,
  TokenSymbol.USDC,
);
// Or let the user toggle: selected = [TokenSymbol.USDC, TokenSymbol.ETH]

const selection = client.coinbase.getSelectionAggregatedBalance({
  balances: raw,
  currency: TokenSymbol.USDC,
  fundingTokens: selected,
});

console.log(selection.balance, selection.formatted.valueFiat);

Use selection.balance with limits so max withdrawable reflects funding tokens.

Errors

These helpers are synchronous and do not throw Coinbase API errors. They require balances you already loaded — if the user is disconnected, load balances first (which can throw COINBASE_NOT_CONNECTED).

See Errors.