Class default

The NDK class is the main entry point to the library.


signer:ready when a signer is ready


  • EventEmitter
    • default



cacheAdapter?: NDKCacheAdapter
clientName?: string
clientNip89?: string
debug: Debugger
devWriteRelaySet?: NDKRelaySet
explicitRelayUrls?: string[]
httpFetch: undefined | ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)

Fetch function to use for HTTP requests.

Type declaration

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optional init: RequestInit

      Returns Promise<Response>


import fetch from "node-fetch";

ndk.httpFetch = fetch;
mutedIds: Map<string, string>
outboxPool?: NDKPool
outboxTracker?: OutboxTracker
pool: NDKPool
relayAuthDefaultPolicy?: NDKAuthPolicy

Default relay-auth policy that will be used when a relay requests authentication, if no other policy is specified for that relay.


Disconnect from relays that request authentication:

ndk.relayAuthDefaultPolicy = NDKAuthPolicies.disconnect(ndk.pool);


Sign in to relays that request authentication:

ndk.relayAuthDefaultPolicy = NDKAuthPolicies.signIn({ndk})


Sign in to relays that request authentication, asking the user for confirmation:

ndk.relayAuthDefaultPolicy = (relay: NDKRelay) => {
const signIn = NDKAuthPolicies.signIn({ndk});
if (confirm(`Relay ${relay.url} is requesting authentication, do you want to sign in?`)) {


  • get activeUser(): undefined | NDKUser
  • Returns undefined | NDKUser

  • set activeUser(user: undefined | NDKUser): void
  • Sets the active user for this NDK instance, typically this will be called when assigning a signer to the NDK instance.

    This function will automatically connect to the user's relays if autoConnectUserRelays is set to true.

    It will also fetch the user's mutelist if autoFetchUserMutelist is set to true.


    Returns void


  • Ensures that a signer is available to sign an event.

    Returns void

  • Connect to relays with optional timeout. If the timeout is reached, the connection will be continued to be established in the background.


    • Optional timeoutMs: number

    Returns Promise<void>

  • Creates a new Nip96 instance for the given domain.


    • domain: string

      Domain to use for nip96 uploads

    Returns Nip96


    Upload a file to a NIP-96 enabled domain:

    const blob = new Blob(["Hello, world!"], { type: "text/plain" });
    const nip96 = ndk.getNip96("");
    await nip96.upload(blob);
  • Get a NDKUser from a NIP05


    • nip05: string

      NIP-05 ID

    • skipCache: boolean = false

      Skip cache

    Returns Promise<undefined | NDKUser>

  • Publish an event to a relay


    • event: NDKEvent

      event to publish

    • Optional relaySet: NDKRelaySet

      explicit relay set to use

    • Optional timeoutMs: number

      timeout in milliseconds to wait for the event to be published

    Returns Promise<Set<NDKRelay>>

    The relays the event was published to


    Use event.publish() instead

Generated using TypeDoc