Skip to main content
Glama

erc721_balanceOf

Check how many ERC721 NFTs a specific address owns from a given smart contract. Use this tool to verify NFT ownership balances on Ethereum networks.

Instructions

Get the number of ERC721 NFTs owned by a specific address. Alternative naming for compatibility with MCP client tests.

Input Schema

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

Implementation Reference

  • Handler function that implements the core logic of the erc721_balanceOf tool by fetching owned tokens via ethersService and computing the balance as the token count.
    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)}` }] }; } }
  • Registration of the erc721_balanceOf tool on the MCP server, including name, description, input schema, and inline handler function.
    // 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)}` }] }; } } );
  • Input schema definition for the erc721_balanceOf tool parameters: tokenAddress, ownerAddress, provider, 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.") },

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