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
Field | Description |
---|---|
balances | The list of EVM token balances. |
amount | Amount of a given token in JSON format, includes amount , denominated in the smallest indivisible unit of the token; and decimals . |
token | General information about a token in JSON format. |
network | Name of the blockchain network, e.g. base . |
symbol | The symbol of the ERC-20 or native gas token, e.g. ETH . |
name | The name of the ERC-20 or native gas token, e.g. Ether . |
contractAddress | Address of the ERC-20 or native gas token smart contract. |
nextPageToken | The token for the next page of items, if any. |
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