Migration Guide: NDK v2.12.x to v2.13.0
This guide outlines the breaking changes introduced in NDK version 2.13.0 and how to update your code.
Breaking Changes
ndk.subscribe() Signature Change
The way explicit relays are specified for a subscription has changed.
Before (v2.12.x and earlier):
The ndk.subscribe() method accepted an optional NDKRelaySet as its third parameter:
typescript
// Old signature
ndk.subscribe(
filters: NDKFilter | NDKFilter[],
opts?: NDKSubscriptionOptions,
relaySet?: NDKRelaySet, // Explicit relay set as 3rd argument
autoStart?: boolean | NDKSubscriptionEventHandlers
): NDKSubscription;
// Example usage
const explicitRelaySet = NDKRelaySet.fromRelayUrls(["wss://explicit.relay"], ndk);
ndk.subscribe(filters, { closeOnEose: true }, explicitRelaySet);After (v2.13.0):
The third parameter (relaySet) has been removed. Instead, you now specify explicit relays directly within the NDKSubscriptionOptions (the second parameter) using either:
relaySet: Pass an existingNDKRelaySetinstance.relayUrls: Pass an array of relay URLs. NDK will create anNDKRelaySetfrom these URLs internally.
If both relaySet and relayUrls are provided in the options, relaySet takes precedence.
typescript
// New signature
ndk.subscribe(
filters: NDKFilter | NDKFilter[],
opts?: NDKSubscriptionOptions, // Includes optional relaySet or relayUrls
autoStart?: boolean | NDKSubscriptionEventHandlers
): NDKSubscription;
// Example usage with relaySet option
const explicitRelaySet = NDKRelaySet.fromRelayUrls(["wss://explicit.relay"], ndk);
ndk.subscribe(filters, { closeOnEose: true, relaySet: explicitRelaySet });
// Example usage with relayUrls option
ndk.subscribe(filters, { closeOnEose: true, relayUrls: ["wss://explicit.relay"] });Migration Steps:
- Identify all calls to
ndk.subscribe()where you were passing anNDKRelaySetas the third argument. - Move the
NDKRelaySetinstance into theoptsobject (the second argument) under therelaySetkey. - Alternatively, if you were creating the
NDKRelaySetjust to pass it in, you can simplify by passing the array of URLs directly using therelayUrlskey in theoptsobject. - Ensure the
autoStartargument (if used) is now the third argument.