Class default

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

signer:ready when a signer is ready

invalid-signature when an event with an invalid signature is received

Hierarchy

  • EventEmitter<{
        event: ((event: NDKEvent, relay: NDKRelay) => void);
        event:invalid-sig: ((event: NDKEvent) => void);
        event:publish-failed: ((event: NDKEvent, error: NDKPublishError, relays: WebSocket["url"][]) => void);
        signer:ready: ((signer: NDKSigner) => void);
        signer:required: (() => void);
    }>
    • default

Constructors

  • Parameters

    Returns default

Properties

asyncSigVerification: boolean = false
autoConnectUserRelays: boolean = true
autoFetchUserMutelist: boolean = true
cacheAdapter?: NDKCacheAdapter
clientName?: string
clientNip89?: string
debug: Debugger
devWriteRelaySet?: NDKRelaySet
fetchEventFromTag: ((...args: [tag: NDKTag, originalEvent: NDKEvent, subOpts?: NDKSubscriptionOptions, fallback: NDKFetchFallbackOptions]) => Promise<null | NDKEvent>) = ...

Attempts to fetch an event from a tag, following relay hints and other best practices.

Type declaration

httpFetch: undefined | {
    (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
    (input: string | URL | Request, init?: RequestInit): Promise<Response>;
}

Fetch function to use for HTTP requests.

Type declaration

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

      • input: URL | RequestInfo
      • Optionalinit: RequestInit

      Returns Promise<Response>

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

      • input: string | URL | Request
      • Optionalinit: RequestInit

      Returns Promise<Response>

import fetch from "node-fetch";

ndk.httpFetch = fetch;
initialValidationRatio: number = 1.0
lowestValidationRatio: number = 1.0
mutedIds: Map<string, string>
netDebug?: NDKNetDebug

Provide a caller function to receive all networking traffic from relays

outboxPool?: NDKPool
outboxTracker?: OutboxTracker
pool: NDKPool
publishingFailureHandled: boolean = false
queuesNip05: Queue<null | ProfilePointer>
queuesZapConfig: Queue<undefined | NDKLnUrlData>
relayAuthDefaultPolicy?: NDKAuthPolicy

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

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

Accessors

  • 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.

    Parameters

    Returns void

  • set signatureVerificationWorker(worker: undefined | Worker): void
  • Parameters

    • worker: undefined | Worker

    Returns void

Methods

  • 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.

    Parameters

    • OptionaltimeoutMs: number

    Returns Promise<void>

  • Creates a new Nip96 instance for the given domain.

    Parameters

    • domain: string

      Domain to use for nip96 uploads

    Returns Nip96

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

    Parameters

    • nip05: string

      NIP-05 ID

    • skipCache: boolean = false

      Skip cache

    Returns Promise<undefined | NDKUser>

  • Creates a new Nostr Wallet Connect instance for the given URI and waits for it to be ready.

    Parameters

    • uri: string

      WalletConnect URI

    • connectTimeout: number | false = 2000

      Timeout in milliseconds to wait for the NWC to be ready. Set to false to avoid connecting.

    Returns Promise<NDKNwc>

    const nwc = await ndk.nwc("nostr+walletconnect://....")
    nwc.payInvoice("lnbc...")
  • Publish an event to a relay

    Parameters

    • event: NDKEvent

      event to publish

    • OptionalrelaySet: NDKRelaySet

      explicit relay set to use

    • OptionaltimeoutMs: 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