ndk icon indicating copy to clipboard operation
ndk copied to clipboard

can't publish event on 2.10.0

Open kuba-04 opened this issue 1 year ago • 3 comments

Everything was working fine on version [2.8.2] but after the upgrade to 2.10.0 I can't publish the event. I do exactly the same thing as before:

let ndk = new NDK({
      explicitRelayUrls: [env.PUBLIC_RELAY_URL],
      signer: signer,   // signer is: new NDKPrivateKeySigner(privateKey)
    });
await ndk.connect();
let metadataEvent = new NDKEvent(ndk);
metadataEvent.kind = 0;
metadataEvent.content = "something";
metadataEvent.publish();

and now getting errors like this: image

why is it getting in this if? image

My client is connected:

  • can see the connection in relay logs
  • if I put wrong url then it fails on connection step

maybe it is very simple, but I don't see it. Takes me too long, so decided to ask for help

kuba-04 avatar Sep 04 '24 08:09 kuba-04

sorry guys, I think this is not NDK version issue. Today I realized the same type event got published but from other page of my app. This must be something related to async javascript issues. Apart from ndk I upgraded also other js libs, also sveltekit stuff. Sorry for bothering, closing this

kuba-04 avatar Sep 06 '24 16:09 kuba-04

Unfortunately this comes back.

  • I checked out old version (old ndk, old svelte) -> working
  • I upgraded svelte libs leaving old ndk, removing all libs and .svelte-kit and reinstalling -> working
  • I upgraded only ndk and the same cleanup as above -> not working image

the only change in code I had to make after upgrade to 2.10.0 was the privKey generation. 2.8.2 had some older version of nostr-tools attached and I used its method generatePrivateKey for a new user. With 2.10.0 I no longer have this lib and I generate the key using NDKPrivateKeySigner.generate().privateKey (but I tried with ). The key prints fine, the ndk connects fine. But I can't publish the event as if during the publishing step there is no connection to that relay, so it doesn't add it to publishedToRelays array so it goes into 7087line if statement. image

I tried to keep ndk 2.10.0 and explicitly use old version of nostr-tools that has that method to keep the code the same. If I did that, still had the same issue with publishing the event. So to me it is evident there is something wrong with ndk or me using it incorrectly.

If you don't mind I will reopen this issue and leave it so maybe someone else has this problem. If this happens to someone else then I might look into the lib and try to find the fix (althought I am not an expert in javascript). For now I will use 2.8.2 version. Also, I doubt there is a bug in 2.10.0 as how would you even publish the version without checking if it works :) There must be something I am doing wrong in the set up. Maybe the documentation is outdated?

kuba-04 avatar Sep 11 '24 07:09 kuba-04

Any chance you can isolate this in a gist that I can run to reproduce the problem?

pablof7z avatar Sep 11 '24 09:09 pablof7z

Perhaps it is something to do with the connect promise returning too early. Try adding a delay to the publish so that it waits until some relays have connected. Worked for me.

setTimeout(async () => {
    const ndkEvent = new NDKEvent(ndk);
    ndkEvent.kind = 1;
    ndkEvent.content = "Hello";
    await ndkEvent.publish();
}, 6000);

jjim1982 avatar Oct 14 '24 07:10 jjim1982

sorry guys for keeping it too long. Let me close it, the app works I can't reproduce

kuba-04 avatar Jan 15 '25 21:01 kuba-04