Skip to main content
Glama

get_wallet_balance

Query cryptocurrency wallet balances across EVM and Solana blockchains by providing a valid wallet address. Returns token amounts and USD values in a formatted table.

Instructions

Query the balance of a specified wallet address across supported EVM and Solana blockchains.

Parameters:
    wallet_address (str): The wallet address to query (e.g., '0x123...' for EVM chains like Ethereum, 
                         Polygon, BSC, or 'DYw8jCT...' for Solana). Must be a valid address for the target chain.

Returns:
    str: Formatted table with balance information (chain, token amount, USD value) for supported chains or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wallet_addressYes

Implementation Reference

  • main.py:112-178 (handler)
    The core handler function for the 'get_wallet_balance' tool. It validates the wallet address, determines if it's EVM or Solana, calls helper functions to query Dune SIM API, processes the balance data, and returns a formatted ASCII table with chain, token amount, and USD value.
    @mcp.tool()
    async def get_wallet_balance(wallet_address: str) -> str:
        """
        Query the balance of a specified wallet address across supported EVM and Solana blockchains.
        
        Parameters:
            wallet_address (str): The wallet address to query (e.g., '0x123...' for EVM chains like Ethereum, 
                                 Polygon, BSC, or 'DYw8jCT...' for Solana). Must be a valid address for the target chain.
        
        Returns:
            str: Formatted table with balance information (chain, token amount, USD value) for supported chains or an error message.
        """
        if not wallet_address:
            return "Error: Wallet address is required."
        
        balance_data = []
        supported_evm_chains = ["ethereum", "polygon", "bsc"]
        
        if is_evm_address(wallet_address):
            result = await query_evm_balance(wallet_address)
            if "error" in result:
                return f"Error querying EVM balance: {result['error']}"
            
            balances = result.get("balances", [])
            if not balances:
                return f"No balance data found for wallet {wallet_address}."
            
            for balance in balances:
                chain = balance.get("chain", "").lower()
                if chain not in supported_evm_chains:
                    continue
                amount = int(balance.get("amount", "0"))
                decimals = balance.get("decimals", 18)
                symbol = balance.get("symbol", "Unknown")
                value_usd = float(balance.get("value_usd", 0))
                # Convert amount to human-readable token quantity
                token_amount = amount / (10 ** decimals)
                balance_data.append([chain, f"{token_amount:.6f} {symbol}", f"${value_usd:.2f}"])
        
        elif is_solana_address(wallet_address):
            result = await query_svm_balance(wallet_address)
            if "error" in result:
                return f"Error querying Solana balance: {result['error']}"
            
            balances = result.get("balances", [])
            if not balances:
                return f"No balance data found for wallet {wallet_address}."
            
            for balance in balances:
                chain = balance.get("chain", "").lower()
                if chain != "solana":
                    continue
                token_amount = float(balance.get("balance", "0"))
                symbol = balance.get("symbol", "Unknown")
                value_usd = float(balance.get("value_usd", 0))
                balance_data.append([chain, f"{token_amount:.6f} {symbol}", f"${value_usd:.2f}"])
        
        else:
            return "Error: Invalid wallet address format. Use EVM (0x...) or Solana (Base58) address."
        
        if not balance_data:
            return f"No supported chain balances found for wallet {wallet_address}."
        
        # Generate ASCII table
        headers = ["Chain", "Token Amount", "USD Value"]
        table = tabulate(balance_data, headers=headers, tablefmt="grid")
        return f"Wallet {wallet_address} balances:\n\n{table}"
  • main.py:25-39 (helper)
    Helper function to fetch EVM chain balances from Dune SIM API, used by get_wallet_balance for EVM addresses.
    async def query_evm_balance(wallet_address: str) -> Dict[str, Any]:
        """Query Dune SIM Balance API for wallet balance on EVM chains."""
        headers = {"X-Sim-Api-Key": DUNE_SIM_API_KEY}
        url = f"{DUNE_SIM_API_URL}/v1/evm/balances/{wallet_address}"
        
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, headers=headers)
                response.raise_for_status()
                return response.json()
            except httpx.HTTPStatusError as e:
                return {"error": f"HTTP error: {str(e)}"}
            except httpx.RequestError as e:
                return {"error": f"Request error: {str(e)}"}
  • main.py:41-55 (helper)
    Helper function to fetch Solana (SVM) balances from Dune SIM API, used by get_wallet_balance for Solana addresses.
    async def query_svm_balance(wallet_address: str) -> Dict[str, Any]:
        """Query Dune SIM Balance API for wallet balance on Solana chain."""
        headers = {"X-Sim-Api-Key": DUNE_SIM_API_KEY}
        url = f"{DUNE_SIM_API_URL}/beta/svm/balances/{wallet_address}"
        
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, headers=headers)
                response.raise_for_status()
                return response.json()
            except httpx.HTTPStatusError as e:
                return {"error": f"HTTP error: {str(e)}"}
            except httpx.RequestError as e:
                return {"error": f"Request error: {str(e)}"}
  • Helper function to validate if a wallet address is EVM-compatible (0x followed by 40 hex chars), used to route queries in get_wallet_balance.
    def is_evm_address(address: str) -> bool:
        """Check if the address is an EVM-compatible address."""
        return bool(re.match(r"^0x[a-fA-F0-9]{40}$", address))
  • Helper function to validate if a wallet address is Solana-compatible (Base58, 32-44 chars), used to route queries in get_wallet_balance.
    def is_solana_address(address: str) -> bool:
        """Check if the address is a Solana-compatible address (Base58, 32-44 characters)."""
        return bool(re.match(r"^[1-9A-HJ-NP-Za-km-z]{32,44}$", address))
  • main.py:112-112 (registration)
    The @mcp.tool() decorator registers the get_wallet_balance function as an MCP tool with the FastMCP server.
    @mcp.tool()
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and adds valuable behavioral context: it discloses the supported blockchains (EVM and Solana), the return format (formatted table with chain, token amount, USD value), and error handling (error message on failure). However, it lacks details on rate limits, authentication needs, or specific error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by structured sections for parameters and returns, with each sentence adding essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (1 parameter, no output schema, no annotations), the description is mostly complete: it covers purpose, parameters, returns, and supported blockchains. However, it could improve by addressing authentication, rate limits, or specific error scenarios for full contextual coverage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description compensates fully for the 0% schema description coverage by providing detailed semantics: it explains the wallet_address parameter with examples for EVM and Solana formats, clarifies it must be valid for the target chain, and specifies the supported chains, adding significant meaning beyond the basic schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Query the balance') and resource ('a specified wallet address across supported EVM and Solana blockchains'), distinguishing it from sibling tools like 'get_wallet_activity' and 'get_wallet_transactions' which focus on different wallet data aspects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying the wallet address parameter and supported blockchains, but does not explicitly state when to use this tool versus alternatives like the sibling tools, nor does it provide context on prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/kukapay/wallet-inspector-mcp'

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