Code Snippets
This section contains a growing collection of code snippets demonstrating how to perform specific tasks with NDK. Each snippet is focused on a single, targeted use case to help you quickly find solutions for common implementation needs.
Categories
Snippets are organized into the following categories:
- User
- Generate Keys - Generate a new key pair and obtain all formats (private key, public key, nsec, npub)
- Get Profile - Fetch and handle user profile information
- Event
- Basic - Generate a basic Nostr event
- Tagging Users and Events - Add tags to mention users and events
- Mobile
- [Basics]
- Initialize NDK + SQLite cache - Set up NDK with SQLite caching for mobile apps
- User
- Loading User Profiles - Efficiently load and cache user profiles in mobile apps
- Events
- Rendering Event Content - Rich text rendering of Nostr event content with mentions, hashtags, and media
- Session
- Login - Handle user authentication with NDK Mobile using various methods (NIP-46, nsec)
- [Basics]
- Wallet
- Connect Nostr Wallet Connect - Connect to an NWC wallet and set it up for zapping
- Using Cashu Wallet - Create and use a Cashu wallet for managing e-cash tokens
- Nutzap Monitor - Track and process Cashu tokens sent via Nostr zaps
- Cashu Deposits - Fund your Cashu wallet using Lightning invoices
- Testing
- Mock Relays - Create and use mock relays for testing NDK applications
- Event Generation - Generate test events with different kinds and content
- Nutzap Testing - Test Cashu token and Nutzap functionality
- Relay Pool Testing - Test relay pool behavior and event handling