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

book: add NIP65 & Relay Messages JavaScript examples #575

Closed

Conversation

RydalWater
Copy link
Contributor

Description

  • Added NIP65 examples in line with python examples
  • Corrected minor typos
  • Replaced previous relay messages example with more comprehensive set
  • Added relevant book text throughout
  • Updated index

Notes to the reviewers

Will keep chipping away for the time being. Let me know if there is anything specific I need to look at though.

Checklist

- Added NIP65 examples in line with python examples
- Corrected minor typos
- Replaced previous relay messages example with more comprehensive set
- Added relevant book text throughout
- Updated index
@RydalWater
Copy link
Contributor Author

Just seen the fail, something about it not liking the lack of a Kind instance for an EventBuilder. Will test it again in the morning, I'm pretty confident the code ran prior to the PR but am still juggling machines given that my Linux machine still doesn't like compiling the WebAssembly.Module().

Anyway will review and report back.

@RydalWater
Copy link
Contributor Author

RydalWater commented Sep 25, 2024

Curious, just re-tested this code and I have no issues running it locally (see image below, where the second JSON is the Tag build method)

image

@yukibtc would you mind running the following on your side and let me know if you have some issues. The book deployment checks seem to be falling over at EventBuilder with Error: expected instance of Kind, though from what I can tell this class takes a number for the kind argument, not a Kind class instance.

const { loadWasmSync, Keys, EventBuilder, Tag, RelayMetadata } = require("@rust-nostr/nostr");

function run(){
    // Load WASM
    loadWasmSync();

    // Generate Keys
    let keys = Keys.generate();

    // Create relay metadata tags
    let tag1 = Tag.relayMetadata("wss://relay.damus.io", RelayMetadata.READ);
    let tag2 = Tag.relayMetadata("wss://relay.primal.net", RelayMetadata.WRITE);
    let tag3 = Tag.relayMetadata("wss://relay.nostr.band", null);

    // Build/sign event
    let kind = 10002;
    let content = "";
    let tags = [tag1, tag2, tag3];
    builder = new EventBuilder(kind, content, tags);
    event = builder.toEvent(keys);

    // Print event as json
    console.log(` Event: ${event.asJson()}`);
}

run();

@yukibtc
Copy link
Member

yukibtc commented Sep 25, 2024

Curious, just re-tested this code and I have no issues running it locally (see image below, where the second JSON is the Tag build method)

image

@yukibtc would you mind running the following on your side and let me know if you have some issues. The book deployment checks seem to be falling over at EventBuilder with Error: expected instance of Kind, though from what I can tell this class takes a number for the kind argument, not a Kind class instance.

const { loadWasmSync, Keys, EventBuilder, Tag, RelayMetadata } = require("@rust-nostr/nostr");

function run(){
    // Load WASM
    loadWasmSync();

    // Generate Keys
    let keys = Keys.generate();

    // Create relay metadata tags
    let tag1 = Tag.relayMetadata("wss://relay.damus.io", RelayMetadata.READ);
    let tag2 = Tag.relayMetadata("wss://relay.primal.net", RelayMetadata.WRITE);
    let tag3 = Tag.relayMetadata("wss://relay.nostr.band", null);

    // Build/sign event
    let kind = 10002;
    let content = "";
    let tags = [tag1, tag2, tag3];
    builder = new EventBuilder(kind, content, tags);
    event = builder.toEvent(keys);

    // Print event as json
    console.log(` Event: ${event.asJson()}`);
}

run();

The kind should be constructed in this way:

let kind = new Kind(10002);

@yukibtc
Copy link
Member

yukibtc commented Sep 25, 2024

I can fix it during cherry-picking

@yukibtc yukibtc closed this in 4b37b8f Sep 25, 2024
yukibtc pushed a commit that referenced this pull request Sep 25, 2024
* Added NIP65 examples in line with python examples
* Corrected minor typos
* Replaced previous relay messages example with more comprehensive set
* Added relevant book text throughout
* Updated index

Closes #575

Signed-off-by: Yuki Kishimoto <[email protected]>
@RydalWater
Copy link
Contributor Author

thanks! Got it sorted, weirdly it wasn't upgrading my package using the normal command. I was rocking v0.33. Had to uninstall the package and re-install the latest. Fixed it though now.

@RydalWater RydalWater deleted the rust-nostr-javascript-examples branch September 26, 2024 19:10
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

Successfully merging this pull request may close these issues.

2 participants