get_nft_metadata
Retrieve metadata for specific NFTs by providing contract address and token ID, supporting ERC721 and ERC1155 token standards.
Instructions
Get metadata for a specific NFT
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | The contract address of the NFT | |
| tokenId | Yes | The token ID of the NFT | |
| tokenType | No | The token type (ERC721 or ERC1155) | |
| refreshCache | No | Whether to refresh the cache |
Implementation Reference
- index.ts:1166-1177 (handler)The handler function for the get_nft_metadata tool. Validates the input parameters using isValidGetNftMetadataParams and calls the Alchemy SDK's nft.getNftMetadata method with contractAddress, tokenId, and additional params.private async handleGetNftMetadata(args: Record<string, unknown>) { const params = this.validateAndCastParams<GetNftMetadataParams>( args, isValidGetNftMetadataParams, "Invalid NFT metadata parameters" ); return await this.alchemy.nft.getNftMetadata( params.contractAddress, params.tokenId, params ); }
- index.ts:55-58 (schema)TypeScript type definition for GetNftMetadataParams, extending GetNftMetadataOptions with required contractAddress and tokenId.type GetNftMetadataParams = GetNftMetadataOptions & { contractAddress: string; tokenId: string; };
- index.ts:118-129 (schema)Validation function for get_nft_metadata parameters, ensuring required fields and types.const isValidGetNftMetadataParams = ( args: any ): args is GetNftMetadataParams => { return ( typeof args === "object" && args !== null && typeof args.contractAddress === "string" && typeof args.tokenId === "string" && (args.tokenType === undefined || typeof args.tokenType === "string") && (args.refreshCache === undefined || typeof args.refreshCache === "boolean") ); };
- index.ts:444-468 (registration)Tool registration in ListTools handler, defining the name, description, and input schema for get_nft_metadata.{ name: "get_nft_metadata", description: "Get metadata for a specific NFT", inputSchema: { type: "object", properties: { contractAddress: { type: "string", description: "The contract address of the NFT", }, tokenId: { type: "string", description: "The token ID of the NFT", }, tokenType: { type: "string", description: "The token type (ERC721 or ERC1155)", }, refreshCache: { type: "boolean", description: "Whether to refresh the cache", }, }, required: ["contractAddress", "tokenId"], },
- index.ts:990-992 (registration)Dispatch case in CallToolRequest handler that routes to the get_nft_metadata handler.case "get_nft_metadata": result = await this.handleGetNftMetadata(request.params.arguments); break;