Skip to main content
Glama

erc721_balanceOf

Check the balance of ERC721 tokens for a specific owner address within an Ethereum-based contract using the MCP Ethers Wallet.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdNoOptional. The chain ID to use.
ownerAddressYesThe address to check balance for
providerNoOptional. The provider to use. If not provided, the default provider is used.
tokenAddressYesThe address of the ERC721 contract

Implementation Reference

  • The main execution handler for the erc721_balanceOf tool. It calls ethersService.getERC721TokensOfOwner to fetch owned tokens and returns the count as the balance in a formatted text response.
    async (params) => { try { // Get the tokens owned by this address const tokens = await ethersService.getERC721TokensOfOwner( params.tokenAddress, params.ownerAddress, false, params.provider, params.chainId ); // The balance is the number of tokens const balance = tokens.length.toString(); return { content: [{ type: "text", text: `${params.ownerAddress} has ${balance} NFTs from contract ${params.tokenAddress}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT balance: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • Zod input schema defining parameters for erc721_balanceOf: tokenAddress (contract), ownerAddress, optional provider and chainId.
    { tokenAddress: contractAddressSchema.describe("The address of the ERC721 contract"), ownerAddress: addressSchema.describe("The address to check balance for"), provider: providerSchema.describe("Optional. The provider to use. If not provided, the default provider is used."), chainId: chainIdSchema.describe("Optional. The chain ID to use.")
  • Direct registration of the erc721_balanceOf tool within registerERC721Tools function using server.tool, including description, schema, and inline handler.
    // Client test compatible version - erc721_balanceOf server.tool( "erc721_balanceOf", "Get the number of ERC721 NFTs owned by a specific address. Alternative naming for compatibility with MCP client tests.", { tokenAddress: contractAddressSchema.describe("The address of the ERC721 contract"), ownerAddress: addressSchema.describe("The address to check balance for"), provider: providerSchema.describe("Optional. The provider to use. If not provided, the default provider is used."), chainId: chainIdSchema.describe("Optional. The chain ID to use.") }, async (params) => { try { // Get the tokens owned by this address const tokens = await ethersService.getERC721TokensOfOwner( params.tokenAddress, params.ownerAddress, false, params.provider, params.chainId ); // The balance is the number of tokens const balance = tokens.length.toString(); return { content: [{ type: "text", text: `${params.ownerAddress} has ${balance} NFTs from contract ${params.tokenAddress}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT balance: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Top-level call to registerERC721Tools in the central tools index, which includes the erc721_balanceOf tool registration.
    registerERC721Tools(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