Relay-Verwaltung
RelayPool umschließt einen kompatiblen PoolLike-Transport deiner App. Konfiguriere urls, verwende subscribe mit onEvent/onEose und schließe Abonnements nach Gebrauch. Ein separat erstellter Relay-Wrapper wird nicht automatisch mit dem Datenprovider verbunden.
Terminal
$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();
};
}