Skip to content

AppleSauceModular SDK for Nostr

Build reactive nostr UI with less code

Core Packages

AppleSauce is built on top of RxJS and uses the observable pattern to provide a reactive, event-driven architecture for Nostr applications.

  • applesauce-core - Essential utilities for working with Nostr events, keys, protocols, and event storage
  • applesauce-relay - Simple relay connection management with automatic reconnection
  • applesauce-signers - Flexible signing interfaces supporting multiple providers
  • applesauce-loaders - High-level data loaders for common Nostr patterns
  • applesauce-factory - Event creation and manipulation utilities

Quick Examples

Subscribe to Events and updating the UI

The event store makes it easy to query and subscribe to events reactively:

typescript
import { EventStore } from "applesauce-core/event-store";

// Create an event store
const store = new EventStore();

// Subscribe to a timeline of kind:1 events (notes)
store.timeline({ kinds: [1], limit: 10 }).subscribe((events) => {
  console.log(`Timeline updated: ${events.length} notes`);

  renderTimeline(events);
});

// Add events to the store - timeline updates automatically
store.add(event);

Fetch Events from Relays

Connect to relays and fetch events with minimal code:

typescript
import { RelayPool, onlyEvents } from "applesauce-relay";

// Create an event store to hold state (events)
const store = new EventStore();

// Create a relay connection
const pool = new RelayPool();

// Subscribe to events from the relay
pool
  .subscription(["wss://relay.damus.io", "wss://nos.lol", "wss://relay.nostr.band"], { kinds: [1], limit: 20 })
  .pipe(onlyEvents())
  .subscribe((event) => store.add(event));

// Subscribe to the timeline from the event store
store.timeline({ kinds: [1] }).subscribe((events) => {
  console.log(`Timeline updated: ${events.length} notes`);
});