Overview
The CDP SDK allows you to retrieve token balances of an address using thelistTokenBalances method for Base. For Solana token balances, use the REST API directly.
Additional information can be found in our SDK Reference.
In this guide, you will learn how to retrieve ERC-20 and native gas token balances of an address on Base networks.
Prerequisites
- Node.js installed
- A free account logged in on CDP Portal and a Secret API key
Configure
1
Install dependencies
2
Create an .env file
Create a
.env file in your project root:3
Add API credentials
If you downloaded your CDP API key as a JSON file, it will look like this. Otherwise, you can copy the values directly from the CDP Portal:Copy these values into your
.env file:Example
In the example below, we query token balances for a known exchange address on Base mainnet.- Token balances: Each ERC-20 token with its amount and contract address
- Contract addresses: The long hex strings identify each specific token contract on Base mainnet
- Large holdings: This exchange wallet holds millions of various tokens
Sample response
The token balance response provides detailed token information:Response fields
Pagination
listTokenBalances supports paginated responses for addresses with many balances:
What to read next
- SDK Reference: SDK documentation for Base
listTokenBalances - Base API Reference: Base REST API endpoint details
- Solana API Reference: Solana REST API endpoint details