Skip to main content
Glama

erc20_balanceOf

Check the balance of a specific ERC20 token for any Ethereum address. Provide the token contract address and owner address, with optional network details, to retrieve accurate token holdings data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdNoOptional. The chain ID to use. If provided with a named network and they don't match, the RPC's chain ID will be used.
ownerAddressYesThe Ethereum address whose balance to check
providerNoOptional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value.
tokenAddressYesThe address of the ERC20 token contract

Implementation Reference

  • The handler function executing the tool logic for erc20_balanceOf. Maps parameters, fetches balance and token info via EthersService, formats response with symbol or error.
    async (params) => { // Map deprecated parameters const mapped = mapParameters(params); try { const contractAddr = mapped.contractAddress || params.tokenAddress; if (!contractAddr) { throw new Error('Either contractAddress or tokenAddress must be provided'); } const balance = await ethersService.getERC20Balance( mapped.ownerAddress, contractAddr, mapped.provider, mapped.chainId ); // Get token info to format the response const tokenInfo = await ethersService.getERC20TokenInfo( contractAddr, mapped.provider, mapped.chainId ); return { content: [{ type: "text", text: `${mapped.ownerAddress} has a balance of ${balance} ${tokenInfo.symbol}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting token balance: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • Input schema using Zod for validating parameters like contractAddress, ownerAddress, provider for the erc20_balanceOf tool.
    { contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated ownerAddress: z.string().describe( "The Ethereum address whose balance to check" ), provider: providerSchema, chainId: chainIdSchema },
  • Registration of the erc20_balanceOf tool using server.tool() within registerERC20Tools function, including name, description, schema, and handler.
    server.tool( "erc20_balanceOf", "Get the ERC20 token balance for a specific address. Alternative naming for compatibility with MCP client tests.", { contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated ownerAddress: z.string().describe( "The Ethereum address whose balance to check" ), provider: providerSchema, chainId: chainIdSchema }, async (params) => { // Map deprecated parameters const mapped = mapParameters(params); try { const contractAddr = mapped.contractAddress || params.tokenAddress; if (!contractAddr) { throw new Error('Either contractAddress or tokenAddress must be provided'); } const balance = await ethersService.getERC20Balance( mapped.ownerAddress, contractAddr, mapped.provider, mapped.chainId ); // Get token info to format the response const tokenInfo = await ethersService.getERC20TokenInfo( contractAddr, mapped.provider, mapped.chainId ); return { content: [{ type: "text", text: `${mapped.ownerAddress} has a balance of ${balance} ${tokenInfo.symbol}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting token balance: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Top-level registration invocation in registerAllTools that calls registerERC20Tools, thereby registering erc20_balanceOf.
    registerERC20Tools(server, ethersService);

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/crazyrabbitLTC/mcp-ethers-server'

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