get-nft-count
Retrieve the number of NFTs held by a specific address on the Monad testnet by providing the address and NFT contract details using this tool.
Instructions
查询 Monad 测试网地址持有的 NFT 数量
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | 需要查询的 Monad 测试网地址 | |
| nftContract | Yes | NFT 合约地址 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"address": {
"description": "需要查询的 Monad 测试网地址",
"type": "string"
},
"nftContract": {
"description": "NFT 合约地址",
"type": "string"
}
},
"required": [
"address",
"nftContract"
],
"type": "object"
}
Implementation Reference
- src/index.ts:85-126 (handler)Handler function that queries the NFT balance for a given address on a specific contract using viem's readContract with the ERC721 balanceOf ABI.async ({ address, nftContract }) => { try { // 调用合约的 balanceOf 方法查询 NFT 数量 const balance = await publicClient.readContract({ address: nftContract as `0x${string}`, abi: [ { inputs: [{ name: "owner", type: "address" }], name: "balanceOf", outputs: [{ name: "", type: "uint256" }], stateMutability: "view", type: "function" } ], functionName: "balanceOf", args: [address as `0x${string}`] }); // 返回格式化的查询结果 return { content: [ { type: "text", text: `地址 ${address} 在合约 ${nftContract} 中持有的 NFT 数量为:${balance.toString()} 个`, }, ], }; } catch (error) { // 错误处理 return { content: [ { type: "text", text: `查询地址 ${address} 的 NFT 数量失败:${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- src/index.ts:80-83 (schema)Zod schema defining the input parameters: address (wallet address) and nftContract (NFT contract address).{ address: z.string().describe("需要查询的 Monad 测试网地址"), nftContract: z.string().describe("NFT 合约地址") },
- src/index.ts:74-126 (registration)Registers the 'get-nft-count' tool on the MCP server with name, description, input schema, and handler function.server.tool( // 功能标识符 "get-nft-count", // 功能说明 "查询 Monad 测试网地址持有的 NFT 数量", // 参数定义 { address: z.string().describe("需要查询的 Monad 测试网地址"), nftContract: z.string().describe("NFT 合约地址") }, // 功能实现 async ({ address, nftContract }) => { try { // 调用合约的 balanceOf 方法查询 NFT 数量 const balance = await publicClient.readContract({ address: nftContract as `0x${string}`, abi: [ { inputs: [{ name: "owner", type: "address" }], name: "balanceOf", outputs: [{ name: "", type: "uint256" }], stateMutability: "view", type: "function" } ], functionName: "balanceOf", args: [address as `0x${string}`] }); // 返回格式化的查询结果 return { content: [ { type: "text", text: `地址 ${address} 在合约 ${nftContract} 中持有的 NFT 数量为:${balance.toString()} 个`, }, ], }; } catch (error) { // 错误处理 return { content: [ { type: "text", text: `查询地址 ${address} 的 NFT 数量失败:${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- src/index.ts:27-28 (registration)Lists 'get-nft-count' as one of the server capabilities.capabilities: ["get-mon-balance", "get-nft-count"] });