Skip to main content
Glama

get-token-balance

Retrieve the ERC-20 token balance for a specific wallet address using MetaMask MCP server, ensuring your private keys remain secure in your crypto wallet.

Instructions

Get token balance of an address.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesAddress to get balance for.
tokenYesERC-20 token address to get balance for.

Implementation Reference

  • Registration of the 'get-token-balance' tool, including name, description, input schema (address and token parameters), and handler logic that uses wagmi's getBalance function to fetch the ERC-20 token balance and returns it as JSON string.
    server.addTool({ name: "get-token-balance", description: "Get token balance of an address.", parameters: z.object({ address: Address.describe("Address to get balance for."), token: Address.describe("ERC-20 token address to get balance for."), }), execute: async (args) => { const result = await getBalance(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify(result), }, ], }; }, });
  • The execute handler for the get-token-balance tool. It calls getBalance from wagmi/core with the wagmiConfig and arguments (address, token), stringifies the result using JSONStringify, and returns it in the MCP content format.
    execute: async (args) => { const result = await getBalance(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify(result), }, ], }; },
  • Zod schema for input parameters: address (wallet address) and token (ERC-20 token contract address).
    parameters: z.object({ address: Address.describe("Address to get balance for."), token: Address.describe("ERC-20 token address to get balance for."), }),

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/Xiawpohr/metamask-mcp'

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