Skip to main content
Glama
getTokenBalancePortfolio.ts2.17 kB
import { z } from "zod"; import axios, { AxiosResponse } from "axios"; import { baseUri, chainName } from "../../constants"; interface HistoricalBalanceResponse { contract: { address: string; decimals: number | null; erc_type: "ERC-20" | "ERC-721" | "ERC-1155"; logoUri: string | null; name: string; symbol: string; }; holdings: { balance: string; raw_balance: string; timestamp: string; }[]; } export default function (server: any) { server.tool( "getTokenBalancePortfolio", "Commonly used to render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.", { chainName: z.literal(chainName), walletAddress: z .string() .describe("Wallet address to fetch token balance for"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get Token Balance Portfolio", readOnlyHint: true, description: "Fetch the token balance portfolio for a specific wallet address.", destructiveHint: false, idempotentHint: true, }, async (args:any) => { const { chainName, walletAddress, authToken } = args; try { const response: AxiosResponse<HistoricalBalanceResponse> = await axios.get( `${baseUri}/${chainName}/v1/address/${walletAddress}/balance/portfolio`, { headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", Accept: "application/json", }, } ); return { content: [ { type: "text", text: `Token Balance Portfolio Data: ${JSON.stringify( response.data )}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching token balance portfolio: ${error}`, }, ], }; } } ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vastavikadi/somnia-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server