Skip to main content
Glama
verifyOwnership.ts3.3 kB
import { Client, Wallet } from "xrpl"; import { z } from "zod"; import { server } from "../../server/server.js"; import { getXrplClient } from "../../core/services/clients.js"; import { MAINNET_URL, TESTNET_URL } from "../../core/constants.js"; import { connectedWallet, isConnectedToTestnet } from "../../core/state.js"; // Register verify-nft-ownership tool server.tool( "verify-nft-ownership", "Verify if an address owns a specific NFT", { address: z .string() .optional() .describe("Account address to check, defaults to connected wallet"), tokenID: z.string().describe("NFT token ID"), useTestnet: z .boolean() .optional() .describe("Whether to use testnet or mainnet"), }, async ({ address, tokenID, useTestnet }) => { let client: Client | null = null; try { const useTestnetNetwork = useTestnet !== undefined ? useTestnet : isConnectedToTestnet; client = await getXrplClient(useTestnetNetwork); // Use provided address or connected wallet's address const accountAddress = address || (connectedWallet ? connectedWallet.address : undefined); if (!accountAddress) { throw new Error("No address provided and no wallet connected."); } // Get account NFTs const accountNfts = await client.request({ command: "account_nfts", account: accountAddress, ledger_index: "validated", }); // Check if the specific NFT is owned const nfts = accountNfts.result.account_nfts || []; const ownsNft = nfts.some((nft) => nft.NFTokenID === tokenID); return { content: [ { type: "text", text: JSON.stringify( { address: accountAddress, tokenID, ownsNft, _meta: { network: useTestnetNetwork ? TESTNET_URL : MAINNET_URL, networkType: useTestnetNetwork ? "testnet" : "mainnet", }, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error verifying NFT ownership: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } finally { if (client) { await client.disconnect(); } } } );

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/RomThpt/mcp-xrpl'

If you have feedback or need assistance with the MCP directory API, please join our Discord server