# NDK (Nostr Development Kit) Claude Skill > **Comprehensive knowledge base for working with NDK in production applications** This Claude skill provides deep expertise in the Nostr Development Kit based on real-world usage patterns from the Plebeian Market application. ## 📚 Documentation Structure ``` .claude/skills/ndk/ ├── README.md # This file - Overview and getting started ├── ndk-skill.md # Complete reference guide (18KB) ├── quick-reference.md # Fast lookup for common tasks (7KB) ├── troubleshooting.md # Common problems and solutions └── examples/ # Production code examples ├── README.md ├── 01-initialization.ts # NDK setup and connection ├── 02-authentication.ts # NIP-07, NIP-46, private keys ├── 03-publishing-events.ts # Creating and publishing events ├── 04-querying-subscribing.ts # Fetching and real-time subs └── 05-users-profiles.ts # User and profile management ``` ## 🚀 Quick Start ### For Quick Lookups Start with **`quick-reference.md`** for: - Common code snippets - Quick syntax reminders - Frequently used patterns ### For Deep Learning Read **`ndk-skill.md`** for: - Complete API documentation - Best practices - Integration patterns - Performance optimization ### For Problem Solving Check **`troubleshooting.md`** for: - Common error solutions - Performance tips - Testing strategies - Debug techniques ### For Code Examples Browse **`examples/`** directory for: - Real production code - Full implementations - React integration patterns - Error handling examples ## 📖 Core Topics Covered ### 1. Initialization & Setup - Basic NDK initialization - Multiple instance patterns (main + zap relays) - Connection management with timeouts - Relay pool configuration - Connection status monitoring ### 2. Authentication - **NIP-07**: Browser extension signers (Alby, nos2x) - **NIP-46**: Remote signers (Bunker) - **Private Keys**: Direct key management - Auto-login with localStorage - Multi-account session management ### 3. Event Publishing - Basic text notes - Parameterized replaceable events (products, profiles) - Order and payment events - Batch publishing - Error handling patterns ### 4. Querying & Subscriptions - One-time fetches with `fetchEvents()` - Real-time subscriptions - Tag filtering patterns - Time-range queries - Event monitoring - React Query integration ### 5. User & Profile Management - Fetch profiles (npub, hex, NIP-05) - Update user profiles - Follow/unfollow operations - Batch profile loading - Profile caching strategies ### 6. Advanced Patterns - Store-based NDK management - Query + subscription combination - Event parsing utilities - Memory leak prevention - Performance optimization ## 🎯 Use Cases ### Building a Nostr Client ```typescript // Initialize const { ndk, isConnected } = await initializeNDK({ relays: ['wss://relay.damus.io', 'wss://nos.lol'], timeoutMs: 10000 }) // Authenticate const { user } = await loginWithExtension(ndk) // Publish await publishBasicNote(ndk, 'Hello Nostr!') // Subscribe const sub = subscribeToNotes(ndk, user.pubkey, (event) => { console.log('New note:', event.content) }) ``` ### Building a Marketplace ```typescript // Publish product await publishProduct(ndk, { slug: 'bitcoin-shirt', title: 'Bitcoin T-Shirt', price: 25, currency: 'USD', images: ['https://...'] }) // Create order await createOrder(ndk, { orderId: uuidv4(), sellerPubkey: merchant.pubkey, productRef: '30402:pubkey:bitcoin-shirt', quantity: 1, totalAmount: '25.00' }) // Monitor payment monitorPaymentReceipt(ndk, orderId, invoiceId, (preimage) => { console.log('Payment confirmed!') }) ``` ### React Integration ```typescript function Feed() { const ndk = useNDK() const { user } = useAuth() // Query with real-time updates const { data: notes } = useNotesWithSubscription( ndk, user.pubkey ) return (