Skip to content

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:

  1. relaySet: Pass an existing NDKRelaySet instance.
  2. relayUrls: Pass an array of relay URLs. NDK will create an NDKRelaySet from 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:

  1. Identify all calls to ndk.subscribe() where you were passing an NDKRelaySet as the third argument.
  2. Move the NDKRelaySet instance into the opts object (the second argument) under the relaySet key.
  3. Alternatively, if you were creating the NDKRelaySet just to pass it in, you can simplify by passing the array of URLs directly using the relayUrls key in the opts object.
  4. Ensure the autoStart argument (if used) is now the third argument.