NDK (Nostr Development Kit) is a comprehensive toolkit for building Nostr applications. It's a monorepo containing everything you need to create modern, performant, and feature-rich Nostr clients, from reactive UI bindings to advanced protocols like Web of Trust and Negentropy sync.
- π Modern & Performant - Built with TypeScript, optimized for real-world use
- π― Framework Integration - First-class support for Svelte 5, React, and React Native
- π Advanced Features - Web of Trust, Negentropy sync, multi-account sessions, wallet integration
- πΎ Flexible Caching - Multiple adapters (Dexie, Redis, SQLite, in-memory, Nostr relay)
- π¦ Modular - Use only what you need, from core to specialized packages
- π¨ Beautiful APIs - Intuitive, well-documented, and type-safe
| Package | Version | Description |
|---|---|---|
@nostr-dev-kit/ndk |
npm | Core NDK library with event handling, subscriptions, and relay management |
| Package | Version | Description |
|---|---|---|
@nostr-dev-kit/svelte |
npm | Modern Svelte 5 integration with reactive runes |
@nostr-dev-kit/react |
npm | React hooks for NDK |
@nostr-dev-kit/mobile |
npm | React Native integration |
| Package | Version | Description |
|---|---|---|
@nostr-dev-kit/messages |
npm | High-level messaging with NIP-17 DMs and conversation management |
@nostr-dev-kit/sessions |
npm | Multi-account session management with persistence |
@nostr-dev-kit/wot |
npm | Web of Trust filtering and ranking |
@nostr-dev-kit/sync |
npm | NIP-77 Negentropy set reconciliation |
@nostr-dev-kit/wallet |
npm | Wallet integration (Cashu, NWC, WebLN) |
@nostr-dev-kit/blossom |
npm | Blossom media server protocol |
| Package | Version | Description |
|---|---|---|
@nostr-dev-kit/cache-memory |
npm | In-memory LRU cache |
@nostr-dev-kit/cache-dexie |
npm | IndexedDB cache using Dexie |
@nostr-dev-kit/cache-redis |
npm | Redis cache for server-side |
@nostr-dev-kit/cache-sqlite |
npm | SQLite cache |
@nostr-dev-kit/cache-sqlite-wasm |
npm | SQLite WASM for web workers |
@nostr-dev-kit/cache-nostr |
npm | Use a Nostr relay as cache |
import { NDKSvelte } from '@nostr-dev-kit/svelte'; import NDKCacheDexie from '@nostr-dev-kit/ndk-cache-dexie'; const ndk = new NDKSvelte({ explicitRelayUrls: ['wss://relay.damus.io', 'wss://relay.nostr.band'], cacheAdapter: new NDKCacheDexie({ dbName: 'my-app' }) }); ndk.connect(); // Reactive subscriptions with Svelte 5 runes const notes = ndk.subscribe({ kinds: [1], limit: 50 }); // Access reactive properties in your template notes.events; // Array of events (reactive) notes.eosed; // EOSE flag (reactive)
import { useSubscription } from '@nostr-dev-kit/react'; function Feed() { const { events, eosed } = useSubscription({ kinds: [1], limit: 50 }); return ( <div> {events.map(event => ( <div key={event.id}>{event.content}</div> ))} </div> ); }
import NDK from '@nostr-dev-kit/ndk'; const ndk = new NDK({ explicitRelayUrls: ['wss://relay.damus.io'] }); await ndk.connect(); const sub = ndk.subscribe({ kinds: [1], limit: 50 }, { onEvent: (event) => { console.log('New note:', event.content); } });
Filter and rank content using social graph analysis:
import { NDKSvelte } from '@nostr-dev-kit/svelte'; const ndk = new NDKSvelte(config); // Load WoT data await ndk.wot.load({ maxDepth: 2 }); // Enable automatic filtering on all subscriptions ndk.wot.enableAutoFilter({ maxDepth: 2, minScore: 0.5, includeUnknown: false }); // All subscriptions now automatically filter by WoT const notes = ndk.subscribe({ kinds: [1] });
Efficient set reconciliation using NIP-77:
import { NDKSync } from '@nostr-dev-kit/sync'; const sync = new NDKSync(ndk); // Sync events efficiently with set reconciliation await sync.syncFilter( { kinds: [1], authors: [pubkey] }, relayUrl, { initialBackfillSeconds: 86400 * 7 } // Last 7 days );
Built-in session management with automatic persistence:
import { NDKNip07Signer } from '@nostr-dev-kit/ndk'; // Login with browser extension const signer = new NDKNip07Signer(); await ndk.sessions.login(signer); // Switch between accounts ndk.sessions.switch(otherPubkey); // Access current user const currentUser = ndk.sessions.currentUser; const profile = ndk.sessions.profile; const follows = ndk.sessions.follows;
Seamless wallet support for Cashu, NWC, and WebLN:
import { NDKCashuWallet } from '@nostr-dev-kit/wallet'; const wallet = new NDKCashuWallet(ndk); await wallet.init(); ndk.wallet.set(wallet); // Reactive balance const balance = ndk.wallet.balance; // Send payments await wallet.cashuPay({ amount: 1000, unit: 'sat', target: event });
- β NIP-01 - Basic protocol
- β NIP-04 - Encrypted Direct Messages
- β NIP-07 - Browser extension signer
- β NIP-17 - Gift-wrap DMs
- β NIP-18 - Repost + Generic Reposts
- β NIP-22 - Generic Comments
- β NIP-23 - Long-form content
- β NIP-29 - Simple groups
- β NIP-42 - Relay authentication
- β NIP-44 - Encrypted payloads
- β
NIP-46 - Remote signing (nsecBunker)
- β Permission tokens
- β OAuth flow
- β NIP-47 - Nostr Wallet Connect
- β NIP-57 - Zaps (LUD06, LUD16)
- β NIP-59 - Gift wraps
- β NIP-60 - Cashu wallet
- β NIP-61 - Nutzaps
- β NIP-65 - Relay list metadata
- β NIP-77 - Negentropy set reconciliation
- β NIP-89 - Application handlers
- β NIP-90 - Data Vending Machines
- Auto-grouping queries
- Auto-closing subscriptions
- Reactive subscriptions
- Buffered updates for performance
- Smart deduplication
- Private key
- Browser extension (NIP-07)
- nsecBunker (NIP-46)
- OAuth flow support
- Outbox model (NIP-65)
- Explicit relay blacklist
- Smart relay selection
- Multiple adapters (memory, IndexedDB, SQLite, Redis)
- Extensible module system for package-specific collections
- Automatic cache invalidation
- Server-side and client-side support
- AI Guardrails - Optional runtime validation to catch common mistakes
- Educational error messages with actionable fixes
- Granular configuration (enable/disable specific checks)
- Zero performance impact when disabled
- Comprehensive Test Utilities - Full mock infrastructure for testing Nostr apps
- Mock relays with network simulation (delays, disconnects, failures)
- Deterministic test users and event factories
- Time control for async testing
- All utilities exported via
@nostr-dev-kit/ndk/test
import { RelayPoolMock, UserGenerator, EventGenerator } from '@nostr-dev-kit/ndk/test'; // Create mock relay environment const pool = new RelayPoolMock(); pool.addMockRelay('wss://relay.example.com'); // Generate test users and events const alice = UserGenerator.getUser('alice', ndk); const event = await EventGenerator.createSignedTextNote('Hello!', alice.pubkey); // Simulate relay behavior const relay = pool.getMockRelay('wss://relay.example.com'); relay.simulateEvent(event); relay.simulateEOSE(); // Test your app's event handling
π Testing Guide - Complete guide to testing your Nostr application
π Full Documentation
Explore working examples in the examples directory:
- Basic Feed - Simple note feed with profiles
- Nutsack - NIP-60 Cashu wallet with payment tracking
- Sessions Demo - Multi-account session management
- Event Graph - Event relationship visualization
See REFERENCES.md for a comprehensive list of production applications built with NDK, including:
- Highlighter - Long-form content platform
- Lume - Desktop Nostr client
- Flockstr - Event management
- Ostrich.work - Project management
- And many more...
NDK is open source and we welcome contributions! Whether it's:
- π Bug reports
- π‘ Feature requests
- π Documentation improvements
- π§ Code contributions
Check out our GitHub repository to get started.
# Clone the repository git clone https://github.com/nostr-dev-kit/ndk.git cd ndk # Install dependencies bun install # Build all packages bun run build # Run tests bun test # Start development mode bun run dev
- GitHub: nostr-dev-kit/ndk
- Documentation: ndk.fyi
- Issues: Bug reports & feature requests
MIT
Built with β€οΈ by @pablof7z and the Nostr community.