Skip to main content
Glama
lienhage

Blockchain MCP Server

by lienhage

Get Balance

get-balance

Check the balance of any address on EVM-compatible chains like Ethereum, Polygon, or BSC. Input chain and address details to retrieve real-time or historical wallet balances.

Instructions

Get the balance of an address on any EVM-compatible chain

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesAddress to check balance for
blockTagNoBlock tag (latest, earliest, pending, or block number)latest
chainYesChain identifier. Available: ethereum, polygon, bsc, arbitrum, optimism, avalanche, fantom, sepolia

Implementation Reference

  • Handler function that retrieves the balance of a given address on the specified EVM chain using the ethers provider.
          async ({ chain, address, blockTag = "latest" }) => {
            try {
              const chainConfig = DEFAULT_CHAINS[chain.toLowerCase()];
              if (!chainConfig) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Unsupported chain "${chain}". Available chains: ${Object.keys(DEFAULT_CHAINS).join(', ')}`
                  }],
                  isError: true
                };
              }
    
              if (!ethers.isAddress(address)) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Invalid address: ${address}`
                  }],
                  isError: true
                };
              }
    
              const provider = this.providers.get(chain.toLowerCase());
              if (!provider) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Provider not initialized for chain: ${chain}`
                  }],
                  isError: true
                };
              }
    
              const balance = await provider.getBalance(address, blockTag);
    
              return {
                content: [{
                  type: "text",
                  text: `Balance Information:
    
    🔗 Chain: ${chainConfig.name} (${chainConfig.chainId})
    👤 Address: ${address}
    🏷️ Block: ${blockTag}
    
    💰 Balance: ${ethers.formatEther(balance)} ${chainConfig.symbol}
    🔢 Wei: ${balance.toString()}
    
    ${chainConfig.explorerUrl ? `🔍 Explorer: ${chainConfig.explorerUrl}/address/${address}` : ''}`
                }]
              };
            } catch (error) {
              return {
                content: [{
                  type: "text",
                  text: `Error getting balance: ${error instanceof Error ? error.message : String(error)}`
                }],
                isError: true
              };
            }
          }
  • Input schema definition for the get-balance tool using Zod, specifying chain, address, and optional blockTag.
    {
      title: "Get Balance",
      description: "Get the balance of an address on any EVM-compatible chain",
      inputSchema: {
        chain: z.string().describe(`Chain identifier. Available: ${Object.keys(DEFAULT_CHAINS).join(', ')}`),
        address: z.string().describe("Address to check balance for"),
        blockTag: z.string().optional().describe("Block tag (latest, earliest, pending, or block number)").default("latest")
      }
    },
  • Registration of the 'get-balance' tool with the MCP server, including schema and handler function.
        server.registerTool(
          "get-balance",
          {
            title: "Get Balance",
            description: "Get the balance of an address on any EVM-compatible chain",
            inputSchema: {
              chain: z.string().describe(`Chain identifier. Available: ${Object.keys(DEFAULT_CHAINS).join(', ')}`),
              address: z.string().describe("Address to check balance for"),
              blockTag: z.string().optional().describe("Block tag (latest, earliest, pending, or block number)").default("latest")
            }
          },
          async ({ chain, address, blockTag = "latest" }) => {
            try {
              const chainConfig = DEFAULT_CHAINS[chain.toLowerCase()];
              if (!chainConfig) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Unsupported chain "${chain}". Available chains: ${Object.keys(DEFAULT_CHAINS).join(', ')}`
                  }],
                  isError: true
                };
              }
    
              if (!ethers.isAddress(address)) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Invalid address: ${address}`
                  }],
                  isError: true
                };
              }
    
              const provider = this.providers.get(chain.toLowerCase());
              if (!provider) {
                return {
                  content: [{
                    type: "text",
                    text: `Error: Provider not initialized for chain: ${chain}`
                  }],
                  isError: true
                };
              }
    
              const balance = await provider.getBalance(address, blockTag);
    
              return {
                content: [{
                  type: "text",
                  text: `Balance Information:
    
    🔗 Chain: ${chainConfig.name} (${chainConfig.chainId})
    👤 Address: ${address}
    🏷️ Block: ${blockTag}
    
    💰 Balance: ${ethers.formatEther(balance)} ${chainConfig.symbol}
    🔢 Wei: ${balance.toString()}
    
    ${chainConfig.explorerUrl ? `🔍 Explorer: ${chainConfig.explorerUrl}/address/${address}` : ''}`
                }]
              };
            } catch (error) {
              return {
                content: [{
                  type: "text",
                  text: `Error getting balance: ${error instanceof Error ? error.message : String(error)}`
                }],
                isError: true
              };
            }
          }
        );
  • Constructor initializes ethers.JsonRpcProvider instances for each supported chain, used by the get-balance handler.
    constructor() {
      // Initialize providers for all default chains
      for (const [key, config] of Object.entries(DEFAULT_CHAINS)) {
        this.providers.set(key, new ethers.JsonRpcProvider(config.rpcUrl));
      }
    }
  • Configuration object defining supported chains with RPC URLs, chain IDs, symbols, and explorer URLs, used to select provider and format responses in get-balance.
    const DEFAULT_CHAINS: Record<string, ChainConfig> = {
      ethereum: {
        name: "Ethereum Mainnet",
        chainId: 1,
        rpcUrl: "https://rpc.ankr.com/eth",
        symbol: "ETH",
        explorerUrl: "https://etherscan.io"
      },
      polygon: {
        name: "Polygon",
        chainId: 137,
        rpcUrl: "https://rpc.ankr.com/polygon",
        symbol: "MATIC",
        explorerUrl: "https://polygonscan.com"
      },
      bsc: {
        name: "BSC",
        chainId: 56,
        rpcUrl: "https://rpc.ankr.com/bsc",
        symbol: "BNB",
        explorerUrl: "https://bscscan.com"
      },
      arbitrum: {
        name: "Arbitrum One",
        chainId: 42161,
        rpcUrl: "https://rpc.ankr.com/arbitrum",
        symbol: "ETH",
        explorerUrl: "https://arbiscan.io"
      },
      optimism: {
        name: "Optimism",
        chainId: 10,
        rpcUrl: "https://rpc.ankr.com/optimism",
        symbol: "ETH",
        explorerUrl: "https://optimistic.etherscan.io"
      },
      avalanche: {
        name: "Avalanche C-Chain",
        chainId: 43114,
        rpcUrl: "https://rpc.ankr.com/avalanche",
        symbol: "AVAX",
        explorerUrl: "https://snowtrace.io"
      },
      fantom: {
        name: "Fantom",
        chainId: 250,
        rpcUrl: "https://rpc.ankr.com/fantom",
        symbol: "FTM",
        explorerUrl: "https://ftmscan.com"
      },
      sepolia: {
        name: "Sepolia Testnet",
        chainId: 11155111,
        rpcUrl: "https://rpc.ankr.com/eth_sepolia",
        symbol: "ETH",
        explorerUrl: "https://sepolia.etherscan.io"
      }
    };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks details on traits like rate limits, authentication needs, error handling, or response format. For a read operation with no annotations, this is a significant gap, as it doesn't clarify if it's safe, fast, or has any constraints beyond the basic functionality.

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 a single, efficient sentence that front-loads the core purpose without waste. It's appropriately sized for a simple tool, with every word contributing to clarity. No unnecessary details or redundancy are present.

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

Completeness3/5

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

Given the tool's low complexity (3 parameters, no output schema, no annotations), the description is minimally complete. It covers the basic purpose but lacks behavioral context and usage guidelines. With no output schema, it doesn't explain return values, which could be a gap, but the simplicity of the tool makes this adequate for a baseline score.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters (address, blockTag, chain) with descriptions. The description adds no additional meaning beyond what's in the schema, such as explaining parameter interactions or examples. Baseline 3 is appropriate when the schema does the heavy lifting, but no extra value is provided.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('balance of an address'), specifying the scope ('on any EVM-compatible chain'). It distinguishes from siblings like 'send-transaction' or 'validate-ethereum-address' by focusing on balance retrieval rather than transaction sending or validation. However, it doesn't explicitly differentiate from 'static-call' which might also retrieve data, making it a 4 rather than a 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an address), exclusions, or comparisons with siblings like 'static-call' for other data retrieval. The context is implied but not explicit, leaving the agent to infer usage based on the purpose alone.

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

Related 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/lienhage/blockchain-mcp'

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