Skip to main content

getPortfolioData

Description

getPortfolioData is a function that returns the ERC20 portfolio data for a given Senpi user using the Zapper V1 API.

You can also get this data directly from state.currentWalletBalance.

Pre-requisites

To use this function for local development, make sure that you have the following environment variables set:

ZAPPER_API_KEY=xxx
ZAPPER_API_URL=https://public.zapper.xyz/graphql

Usage

import { getPortfolioData } from "@moxie-protocol/moxie-agent-lib";

const portfolioData = await getPortfolioData(
["0x0000000000000000000000000000000000000000"], // user's wallet addresses
["BASE_MAINNET"],
"M1", // Senpi User ID
runtime // IAgentRuntime
);

Response

{
tokenBalances: [
{
address: "0x0000000000000000000000000000000000000000",
network: "BASE_MAINNET",
token: {
balance: 1000000000000000000,
balanceUSD: 1000000000000000000,
baseToken: {
name: "ETH",
address: "0x0000000000000000000000000000000000000000",
symbol: "ETH",
},
},
},
],
}

Type Signature

export async function getPortfolioData(
addresses: string[],
networks: string[],
userId: string,
runtime: IAgentRuntime
): Promise<Portfolio>;

Parameters

ParameterTypeDescription
addressesstring[]The addresses of the wallets to get the portfolio data for
networksstring[]The networks to get the portfolio data for
userIdstringThe Senpi user ID to get the portfolio data for
runtimeIAgentRuntimeThe runtime to get the portfolio data for

Fields

FieldTypeDescription
tokenBalancesTokenBalance[]The token balances for the given user