fetch-profile.ts
Nostr Agent Onboarding · start here · all examples · source:
nostr-dev/sdk/examples/fetch-profile.ts· snapshot 2026-10-10
Fetch a kind 0 profile.
import NDK from "@nostr-dev-kit/ndk";
const npubOrHex = process.argv[2] ?? "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6";
const ndk = new NDK({
explicitRelayUrls: [
"wss://relay.ngit.dev",
"wss://relay.damus.io",
"wss://nos.lol",
"wss://relay.nostr.band",
],
});
await ndk.connect(2000);
const user = ndk.getUser({ npub: npubOrHex.startsWith("npub") ? npubOrHex : undefined, pubkey: npubOrHex.startsWith("npub") ? undefined : npubOrHex });
const profile = await user.fetchProfile();
console.log(`pubkey: ${user.pubkey}`);
console.log(`name: ${profile?.name}`);
console.log(`display: ${profile?.displayName}`);
console.log(`about: ${profile?.about?.slice(0, 200)}`);
console.log(`nip05: ${profile?.nip05}`);
console.log(`picture: ${profile?.picture}`);
process.exit(0);