Skip to main content
Glama

getNFTInfo

Retrieve basic details about an ERC721 NFT collection, including name, symbol, and total supply, by providing the contract address.

Instructions

Get information about an ERC721 NFT collection including its name, symbol, and total supply. Provides basic details about the NFT contract.

Input Schema

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

Implementation Reference

  • The MCP tool handler function that executes the getNFTInfo tool logic. Fetches NFT collection information using ethersService and returns a formatted text response or error.
    async (params) => { try { const info = await ethersService.getERC721CollectionInfo( params.contractAddress, params.provider, params.chainId ); return { content: [{ type: "text", text: `NFT Information: Name: ${info.name} Symbol: ${info.symbol} Total Supply: ${info.totalSupply}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT information: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • Registration of the getNFTInfo tool with the MCP server inside registerERC721Tools function, including name, description, input schema, and handler reference.
    server.tool( "getNFTInfo", "Get information about an ERC721 NFT collection including its name, symbol, and total supply. Provides basic details about the NFT contract.", { contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"), 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 { const info = await ethersService.getERC721CollectionInfo( params.contractAddress, params.provider, params.chainId ); return { content: [{ type: "text", text: `NFT Information: Name: ${info.name} Symbol: ${info.symbol} Total Supply: ${info.totalSupply}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT information: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Input schema for the getNFTInfo tool using Zod schemas for contractAddress, provider, and chainId.
    { contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"), 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.") },
  • Supporting helper function getNFTInfo that retrieves basic ERC721 collection information (name, symbol, totalSupply) with rate limiting, caching, error handling, and metrics. Used internally by ethersService.getERC721CollectionInfo.
    export async function getNFTInfo( ethersService: EthersService, contractAddress: string, provider?: string, chainId?: number ): Promise<ERC721Info> { metrics.incrementCounter('erc721.getNFTInfo'); return timeAsync('erc721.getNFTInfo', async () => { try { // Check rate limiting const identity = `${contractAddress}:${provider || 'default'}`; if (!rateLimiter.consume('token', identity)) { throw new ERC721Error('Rate limit exceeded for NFT operations'); } // Create cache key const cacheKey = createTokenCacheKey( CACHE_KEYS.ERC721_INFO, contractAddress, chainId ); // Check cache first const cachedInfo = contractCache.get(cacheKey); if (cachedInfo) { return cachedInfo as ERC721Info; } // Get provider from ethers service const ethersProvider = ethersService['getProvider'](provider, chainId); // Check if address is contract const code = await ethersProvider.getCode(contractAddress); if (code === '0x' || code === '0x0') { throw new TokenNotFoundError(contractAddress); } // Create contract instance const contract = new ethers.Contract(contractAddress, ERC721_ABI, ethersProvider); // Fetch NFT information - some contracts might not implement all methods let name = ''; let symbol = ''; let totalSupply: string | undefined = undefined; try { name = await contract.name(); } catch (error) { logger.debug('Error getting NFT name', { contractAddress, error }); name = 'Unknown Collection'; } try { symbol = await contract.symbol(); } catch (error) { logger.debug('Error getting NFT symbol', { contractAddress, error }); symbol = 'NFT'; } try { // totalSupply is optional in ERC721 const supplyBigInt = await contract.totalSupply(); totalSupply = supplyBigInt.toString(); } catch (error) { // totalSupply function is not required in ERC721, so ignore errors logger.debug('NFT contract does not implement totalSupply', { contractAddress }); } // Format data const nftInfo: ERC721Info = { name, symbol, totalSupply }; // Cache result for future use (1 hour TTL) contractCache.set(cacheKey, nftInfo, { ttl: 3600000 }); return nftInfo; } catch (error) { logger.debug('Error getting ERC721 NFT info', { contractAddress, error }); if (error instanceof TokenNotFoundError) { throw error; } throw handleTokenError(error, 'Failed to get NFT collection information'); } }); }

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