Skip to main content
Glama
RWAValueRouter

ValueRouter MCP Server

get_user_balance

Retrieve token balances for specific users on designated blockchain networks to monitor holdings and verify transaction eligibility.

Instructions

Get user token balance on a specific chain

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdYesChain ID to check balance on
tokenAddressYesToken contract address
userAddressYesUser address to check balance for

Implementation Reference

  • src/index.ts:265-290 (registration)
    Registration of the 'get_user_balance' tool including name, description, and input schema definition.
    { name: 'get_user_balance', description: 'Get user token balance on a specific chain', inputSchema: { type: 'object', properties: { chainId: { oneOf: [ { type: 'number' }, { type: 'string' }, ], description: 'Chain ID to check balance on', }, tokenAddress: { type: 'string', description: 'Token contract address', }, userAddress: { type: 'string', description: 'User address to check balance for', }, }, required: ['chainId', 'tokenAddress', 'userAddress'], additionalProperties: false, }, },
  • Zod input schema (BalanceQuerySchema) used for validating get_user_balance tool arguments.
    export const BalanceQuerySchema = z.object({ chainId: z.union([z.number(), z.string()]), tokenAddress: z.string(), userAddress: z.string(), }); export type BalanceQuery = z.infer<typeof BalanceQuerySchema>;
  • Main tool handler 'getUserBalance' that parses input schema and calls BalanceService for execution.
    private async getUserBalance(args: any): Promise<MCPToolResult> { try { const request = BalanceQuerySchema.parse(args); const result = await this.balanceService.getBalance(request); return createSuccessResponse(result); } catch (error) { return createErrorResponse( error instanceof Error ? error.message : String(error), 'BALANCE_ERROR' ); } }
  • Core balance fetching logic in BalanceService.getBalance, dispatching to chain-specific balance retrievers.
    async getBalance(query: BalanceQuery): Promise<BalanceResponse> { const { chainId, tokenAddress, userAddress } = query; const chainIdTyped = chainId as SupportedChainId; try { if (isEVMChain(chainIdTyped)) { return await this.getEVMBalance(chainIdTyped, tokenAddress, userAddress); } else if (isSolanaChain(chainIdTyped)) { return await this.getSolanaBalance(chainIdTyped, tokenAddress, userAddress); } else if (isSuiChain(chainIdTyped)) { return await this.getSuiBalance(chainIdTyped, tokenAddress, userAddress); } else if (isCosmosChain(chainIdTyped)) { return await this.getCosmosBalance(chainIdTyped, tokenAddress, userAddress); } else { throw new Error(`Unsupported chain: ${chainId}`); } } catch (error) { throw new Error(`Failed to get balance: ${error instanceof Error ? error.message : String(error)}`); } }
  • Zod output schema (BalanceResponseSchema) defining the structure of balance query results.
    export const BalanceResponseSchema = z.object({ chainId: z.union([z.number(), z.string()]), tokenAddress: z.string(), balance: z.string(), decimals: z.number(), symbol: z.string(), formattedBalance: z.string(), }); export type BalanceResponse = z.infer<typeof BalanceResponseSchema>;

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/RWAValueRouter/MCP'

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