Skip to main content
Glama

get_token_balance

Retrieve the balance of a specific token for a given address across different blockchain networks using chain ID, token address, and wallet address details.

Instructions

Get the balance of a specific token for a specific address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe address to check the balance for
chain_idYesThe chain ID
token_addressYesThe address of the token

Implementation Reference

  • Handler function that executes the get_token_balance tool by querying the Etherscan API for the token balance of a given address on a specific chain.
    async function handleGetTokenBalance(req: any, apiKey: string) { const chainId = req.params.arguments.chain_id; const tokenAddress = req.params.arguments.token_address; const address = req.params.arguments.address; try { const response = await axios.get( `https://api.etherscan.io/v2/api?chainid=${chainId}&module=account&action=tokenbalance&contractaddress=${tokenAddress}&address=${address}&tag=latest&apikey=${apiKey}` ); if (response.data.status === "1") { const balance = response.data.result; return { content: [ { type: "text", text: `Balance of token ${tokenAddress} for address ${address} on chain ${chainId}: ${balance}`, }, ], }; } else { return { content: [ { type: "text", text: `Failed to get token balance: ${response.data.message}`, }, ], }; } } catch (error) { return { content: [ { type: "text", text: `Failed to get token balance: ${error}`, }, ], }; } }
  • ToolDefinition object defining the input schema, name, and description for the get_token_balance tool.
    const getTokenBalance: ToolDefinition = { name: "get_token_balance", description: "Get the balance of a specific token for a specific address", inputSchema: { type: "object", properties: { chain_id: { type: "integer", description: "The chain ID", }, token_address: { type: "string", description: "The address of the token", }, address: { type: "string", description: "The address to check the balance for", }, }, required: ["chain_id", "token_address", "address"], }, };
  • index.ts:216-223 (registration)
    Registration of the get_token_balance tool in the toolDefinitions dictionary used for MCP capabilities and list tools.
    const toolDefinitions: { [key: string]: ToolDefinition } = { [getFilteredRpcList.name]: getFilteredRpcList, [getChainId.name]: getChainId, [getTotalSupply.name]: getTotalSupply, [getTokenBalance.name]: getTokenBalance, [getTokenHolders.name]: getTokenHolders, [getTokenHoldersCount.name]: getTokenHoldersCount };
  • index.ts:505-512 (registration)
    MCP server initialization providing toolDefinitions (including get_token_balance) in capabilities.
    const server = new Server({ name: "etherscan-mcp", version: "1.0.3" }, { capabilities: { tools: toolDefinitions, } });
  • index.ts:485-486 (registration)
    Dispatch case in callToolHandler switch statement routing get_token_balance calls to the handler.
    case getTokenBalance.name: return await handleGetTokenBalance(req, apiKey);

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/septemhill/etherscan-mcp'

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