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
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Address to get balance for. | |
| token | Yes | ERC-20 token address to get balance for. |
Implementation Reference
- src/tools/get-balance.ts:28-46 (registration)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), }, ], }; }, });
- src/tools/get-balance.ts:35-45 (handler)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), }, ], }; },
- src/tools/get-balance.ts:31-34 (schema)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."), }),