Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't publish event on 2.10.0 #268

Open
kuba-04 opened this issue Sep 4, 2024 · 4 comments
Open

can't publish event on 2.10.0 #268

kuba-04 opened this issue Sep 4, 2024 · 4 comments

Comments

@kuba-04
Copy link

kuba-04 commented Sep 4, 2024

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
Copy link
Author

kuba-04 commented Sep 6, 2024

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 kuba-04 closed this as completed Sep 6, 2024
@kuba-04
Copy link
Author

kuba-04 commented Sep 11, 2024

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 kuba-04 reopened this Sep 11, 2024
@pablof7z
Copy link
Collaborator

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

@jjim1982
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants