get_token_balance
Retrieve the token balance for a specific Ethereum address using the Etherscan MCP. Input chain ID, token address, and wallet address to obtain accurate balance details.
Instructions
Get the balance of a specific token for a specific address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The address to check the balance for | |
| chain_id | Yes | The chain ID | |
| token_address | Yes | The address of the token |
Implementation Reference
- src/core/tools/tokensTools.ts:21-33 (registration)Registers the 'account__tokenbalance' tool, which is the implementation for getting the balance of an ERC-20 token for a specific address. This matches the functionality of 'get_token_balance'.server.addTool({ name: "account__tokenbalance", description: "Returns the current balance of an ERC-20 token of an address.", parameters: z.object({ contractaddress: z.string().describe("the `contract address` of the ERC-20 token"), address: z.string().describe("the `string` representing the address to check for token balance"), chainid: z.string().optional().default("1").describe("chain id, default 1 ( Ethereum )"), }), execute: async (params) => { const fullParams = { ...params, module: "account", action: "tokenbalance", tag: "latest" }; return await apiCall(fullParams); } });
- src/core/tools/tokensTools.ts:29-32 (handler)The execute handler logic that calls the Etherscan API with module 'account' and action 'tokenbalance' to retrieve the token balance.execute: async (params) => { const fullParams = { ...params, module: "account", action: "tokenbalance", tag: "latest" }; return await apiCall(fullParams); }
- src/core/tools.ts:16-16 (registration)Higher-level registration call that invokes registerTokensTools, including the get_token_balance tool.tools.registerTokensTools(server);
- src/core/tools/utils.ts:48-51 (helper)Helper function apiCall used by all tools, including tokenbalance, to make the API request to Etherscan and format response.export async function apiCall(params = {}): Promise<TextContent> { const data = await makeApiRequest(params); return formatResponse(data); }
- src/core/tools/tokensTools.ts:24-28 (schema)Zod schema for input parameters of the token balance tool.parameters: z.object({ contractaddress: z.string().describe("the `contract address` of the ERC-20 token"), address: z.string().describe("the `string` representing the address to check for token balance"), chainid: z.string().optional().default("1").describe("chain id, default 1 ( Ethereum )"), }),