get_portfolio_tokens
Retrieve token holdings with balances, prices, and metadata for wallet addresses to analyze DeFi portfolios across multiple blockchain networks.
Instructions
Get tokens with balances, prices, and metadata for wallet addresses (uses USER_ADDRESS from env if addresses not provided)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addresses | No | Array of address and networks pairs (max 3 addresses, max 20 networks each). Optional - uses USER_ADDRESS from env if not provided | |
| networks | No | Network identifiers to use with USER_ADDRESS (e.g., 'eth-mainnet', 'base-mainnet'). Only used when addresses not provided. Defaults to ['eth-mainnet', 'base-mainnet'] | |
| withMetadata | No | Include token metadata (optional, default: true) | |
| withPrices | No | Include token prices (optional, default: true) | |
| includeNativeTokens | No | Include native tokens like ETH (optional, default: false) |
Implementation Reference
- src/services/agService.js:247-278 (helper)Supporting function in AgService that makes the actual API call to the aggregator's /api/portfolio/tokens endpoint.
async getPortfolioTokens(addresses, options = {}) { try { const requestBody = { addresses, withMetadata: options.withMetadata, withPrices: options.withPrices, includeNativeTokens: options.includeNativeTokens }; const response = await fetch(`${this.baseUrl}/api/portfolio/tokens`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'Portfolio tokens request failed'); } return data.data; } catch (error) { throw new Error(`Failed to get portfolio tokens: ${error.message}`); } }