Nostr WoT

Camada de dados

Funções independentes buscam perfis, notas, conversas, seguimentos e interações. Os hooks React adicionam um cache que retorna dados armazenados enquanto os revalida. As funções de dados compartilham seu próprio pool de conexões.

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>;
}