Optional
cacheOptional
clientOptional
clientOptional
devOptional
explicitFetch function to use for HTTP requests.
Optional
init: RequestInitimport fetch from "node-fetch";
ndk.httpFetch = fetch;
Optional
outboxOptional
outboxOptional
relayDefault 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?`)) {
signIn(relay);
}
}
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.
Adds an explicit relay to the pool.
Optional
relayAuthPolicy: NDKAuthPolicyAuthentication policy to use if different from the default
Whether to connect to the relay automatically
Fetch a single event.
event id in bech32 format or filter
Optional
opts: NDKSubscriptionOptionssubscription options
Optional
relaySetOrRelay: NDKRelay | NDKRelaySetexplicit relay set to use
Fetch events
Optional
opts: NDKSubscriptionOptionsOptional
relaySet: NDKRelaySetCreates a new Nip96 instance for the given domain.
Domain to use for nip96 uploads
Upload a file to a NIP-96 enabled domain:
const blob = new Blob(["Hello, world!"], { type: "text/plain" });
const nip96 = ndk.getNip96("nostrcheck.me");
await nip96.upload(blob);
Publish an event to a relay
event to publish
Optional
relaySet: NDKRelaySetexplicit relay set to use
Optional
timeoutMs: numbertimeout in milliseconds to wait for the event to be published
The relays the event was published to
Use event.publish()
instead
Create a new subscription. Subscriptions automatically start, you can make them automatically close when all relays send back an EOSE by setting opts.closeOnEose
to true
)
Optional
opts: NDKSubscriptionOptionsOptional
relaySet: NDKRelaySetexplicit relay set to use
automatically start the subscription
NDKSubscription
Generated using TypeDoc
The NDK class is the main entry point to the library.
Emits
signer:ready when a signer is ready