Datenschicht
Eigenständige Funktionen laden Profile, Notizen, Threads, Follows und Interaktionen. React-Hooks ergänzen einen Cache, der gespeicherte Daten während der Aktualisierung zurückgibt. Die Datenfunktionen teilen einen eigenen Verbindungspool.
Terminal
$npm install nostr-wot-sdk@3.0.0 nostr-tools
typescript
import {
fetchProfile, fetchNotesByAuthor, fetchEngagement, setDefaultRelays,
} from "nostr-wot-sdk/data";
setDefaultRelays(["wss://relay.damus.io", "wss://nos.lol"]);
async function loadAuthor(pubkey: string) {
const profile = await fetchProfile(pubkey);
const notes = await fetchNotesByAuthor(pubkey, { limit: 50 });
const engagement = await fetchEngagement(notes.map(note => note.id));
return { profile, notes, engagement };
}tsx
"use client";
import { useProfile } from "nostr-wot-sdk/data/react";
function ProfileCard({ pubkey }: { pubkey: string }) {
const profile = useProfile(pubkey);
if (!profile) return null;
return <h2>{profile.displayName ?? profile.name ?? pubkey}</h2>;
}