> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# getCoinbaseAccounts

# getCoinbaseAccounts

Retrieves the authenticated user's Coinbase exchange accounts with their balances. Each account contains multiple currency balances representing the user's holdings on Coinbase.

Use this function to display available funds and to get the `accountId` required for [`createCoinbaseExchangeTransfer`](/docs/javascript/funding/create-coinbase-exchange-transfer).

## Usage

```javascript theme={"system"}
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

const accounts = await getCoinbaseAccounts();

accounts.forEach(account => {
  console.log(`Account: ${account.name || account.id}`);
  account.balances.forEach(balance => {
    console.log(`  ${balance.currency}: ${balance.balance}`);
  });
});
```

## Parameters

| Parameter          | Type                                   | Description                                                                            |
| ------------------ | -------------------------------------- | -------------------------------------------------------------------------------------- |
| `params`           | `GetCoinbaseAccountsParams` (optional) | Optional filters for the accounts.                                                     |
| `params.chainName` | `Chain` (optional)                     | Filter by blockchain (e.g., `'EVM'`, `'SOL'`, `'BTC'`).                                |
| `params.networkId` | `number` (optional)                    | Filter by network ID (e.g., `1` for Ethereum mainnet). Must be a non-negative integer. |
| `client`           | `DynamicClient` (optional)             | The Dynamic client instance. Only required when using multiple clients.                |

## Returns

`Promise<CoinbaseAccount[]>` - A promise that resolves to an array of Coinbase accounts:

```typescript theme={"system"}
type CoinbaseAccount = {
  id: string;                // Unique account ID (use this for transfers)
  exchange: 'coinbase';
  type?: string;             // Account type as reported by Coinbase
  name?: string;             // Human-friendly label, if Coinbase supplied one
  chain?: string;            // Blockchain network if relevant
  balances: Array<{
    currency: string;        // Currency code (e.g., 'ETH', 'BTC', 'USDC')
    balance: number;         // Total balance
    availableBalance?: number; // Balance immediately available for withdrawal
    logoURI?: string;        // Token logo URL
  }>;
};
```

## Errors

| Error               | When it's thrown                                                                   |
| ------------------- | ---------------------------------------------------------------------------------- |
| `InvalidParamError` | `chainName` isn't a recognized chain, or `networkId` isn't a non-negative integer. |

## Examples

### Get all accounts

```javascript theme={"system"}
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

const accounts = await getCoinbaseAccounts();

accounts.forEach(account => {
  console.log(`Account: ${account.name || account.type || account.id}`);
  account.balances.forEach(({ currency, balance, availableBalance }) => {
    console.log(`  ${currency}: ${balance}`);
    if (availableBalance !== undefined && availableBalance !== balance) {
      console.log(`    Available: ${availableBalance}`);
    }
  });
});
```

### Filter by blockchain

```javascript theme={"system"}
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

// Get only EVM-compatible assets (ETH, ERC-20 tokens, etc.)
const evmAccounts = await getCoinbaseAccounts({ chainName: 'EVM' });

// Get only Solana assets
const solanaAccounts = await getCoinbaseAccounts({ chainName: 'SOL' });
```

### Filter by network

```javascript theme={"system"}
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

// Get assets on Ethereum mainnet only
const mainnetAccounts = await getCoinbaseAccounts({
  chainName: 'EVM',
  networkId: 1,
});

// Get assets on Polygon
const polygonAccounts = await getCoinbaseAccounts({
  chainName: 'EVM',
  networkId: 137,
});
```

### Check if user has sufficient balance

```javascript theme={"system"}
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

const hasSufficientBalance = async (currency, requiredAmount) => {
  const accounts = await getCoinbaseAccounts();

  for (const account of accounts) {
    const balance = account.balances.find(b => b.currency === currency);
    if (balance) {
      const available = balance.availableBalance ?? balance.balance;
      if (available >= requiredAmount) {
        return { hasBalance: true, accountId: account.id, available };
      }
    }
  }

  return { hasBalance: false, accountId: null, available: 0 };
};

// Usage
const { hasBalance, accountId } = await hasSufficientBalance('USDC', 100);
if (hasBalance) {
  console.log(`Ready to transfer from account ${accountId}`);
}
```

### Display balances in React

```javascript theme={"system"}
import { useState, useEffect } from 'react';
import { getCoinbaseAccounts } from '@dynamic-labs-sdk/client';

const CoinbaseBalances = () => {
  const [accounts, setAccounts] = useState([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    const fetchBalances = async () => {
      try {
        const data = await getCoinbaseAccounts();
        setAccounts(data);
      } catch (err) {
        setError(err.message);
      } finally {
        setLoading(false);
      }
    };

    fetchBalances();
  }, []);

  if (loading) return <div>Loading balances...</div>;
  if (error) return <div>Error: {error}</div>;
  if (accounts.length === 0) return <div>No Coinbase accounts found</div>;

  return (
    <div>
      <h3>Your Coinbase Balances</h3>
      {accounts.map(account => (
        <div key={account.id}>
          <h4>{account.name || `Account ${account.id.slice(0, 8)}`}</h4>
          <ul>
            {account.balances
              .filter(b => b.balance > 0)
              .map(balance => (
                <li key={balance.currency}>
                  <strong>{balance.currency}:</strong> {balance.balance}
                </li>
              ))}
          </ul>
        </div>
      ))}
    </div>
  );
};
```

## Prerequisites

* User must have connected their Coinbase account through Dynamic
* User must be authenticated

## Related

* [`createCoinbaseExchangeTransfer`](/docs/javascript/funding/create-coinbase-exchange-transfer) - Transfer crypto from Coinbase
