Nostr WoT

Gestione dei relay

RelayPool incapsula un trasporto PoolLike compatibile fornito dalla tua app. Configura urls, usa subscribe con onEvent/onEose e chiudi le sottoscrizioni al termine. Un wrapper relay creato separatamente non si collega automaticamente al provider dei dati.

terminale
$npm install nostr-wot-sdk@3.0.0 nostr-tools
typescript
import { RelayPool, type PoolLike, type NostrEvent } from "nostr-wot-sdk/relay";

function watchNotes(transport: PoolLike, onEvent: (event: NostrEvent) => void) {
  const pool = new RelayPool({
    urls: ["wss://relay.damus.io", "wss://nos.lol"],
    pool: transport,
  });
  const sub = pool.subscribe({ kinds: [1], limit: 50 }, { onEvent });
  return () => {
    sub.close();
    pool.destroy();
  };
}