getNFTOwner
Retrieve the owner of an ERC721 NFT by providing the contract address and token ID using an Ethereum provider on the MCP Ethers Wallet server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No | Optional. The chain ID to use. | |
| contractAddress | Yes | The address of the ERC721 contract | |
| provider | No | Optional. The provider to use. If not provided, the default provider is used. | |
| tokenId | Yes | The ID of the token to check |
Implementation Reference
- src/tools/erc721.ts:152-176 (handler)Handler function that executes the getNFTOwner tool. Calls EthersService.getERC721Owner to fetch the owner address of the specified NFT token and returns a formatted text response or error.async (params) => { try { const owner = await ethersService.getERC721Owner( params.contractAddress, params.tokenId, params.provider, params.chainId ); return { content: [{ type: "text", text: `Owner of token ${params.tokenId} is ${owner}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT owner: ${error instanceof Error ? error.message : String(error)}` }] }; } }
- src/tools/erc721.ts:47-52 (schema)TypeScript interface defining the input parameters for the getNFTOwner tool.type GetNFTOwnerParams = { contractAddress: string; tokenId: string | number; provider?: string; chainId?: number; };
- src/tools/erc721.ts:143-177 (registration)Registration of the getNFTOwner tool on the MCP server, including tool name, description, input schema (Zod), and handler function.server.tool( "getNFTOwner", "Get the current owner of a specific ERC721 NFT token. Returns the Ethereum address that owns the specified token ID.", { contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"), tokenId: tokenIdSchema.describe("The ID of the token to check"), 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 owner = await ethersService.getERC721Owner( params.contractAddress, params.tokenId, params.provider, params.chainId ); return { content: [{ type: "text", text: `Owner of token ${params.tokenId} is ${owner}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT owner: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
- src/tools/index.ts:25-25 (registration)Calls registerERC721Tools to register all ERC721 tools including getNFTOwner.registerERC721Tools(server, ethersService);