Skip to content

Commit

Permalink
book: add JS hello example
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 19, 2024
1 parent 1b2778e commit 9be15a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
22 changes: 22 additions & 0 deletions book/snippets/js/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ANCHOR: full
import {Keys, Client, EventBuilder, NostrSigner} from "@rust-nostr/nostr-sdk";

export async function hello() {
// ANCHOR: client
let keys: Keys = Keys.generate();
let signer = NostrSigner.keys(keys);
let client = new Client(signer);
// ANCHOR_END: client

// ANCHOR: connect
await client.addRelay("wss://relay.damus.io")

await client.connect();
// ANCHOR_END: connect

// ANCHOR: publish
let builder = EventBuilder.textNote("Hello, rust-nostr!", []);
await client.sendEventBuilder(builder);
// ANCHOR_END: publish
}
// ANCHOR_END: full
16 changes: 12 additions & 4 deletions book/src/sdk/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Now that you’ve installed the SDK, it’s time to write your first nostr progr
<div slot="title">JavaScript</div>
<section>

TODO
```typescript,ignore
{{#include ../../snippets/js/src/hello.ts:client}}
```

</section>

Expand Down Expand Up @@ -78,7 +80,9 @@ TODO
<div slot="title">JavaScript</div>
<section>

TODO
```typescript,ignore
{{#include ../../snippets/js/src/hello.ts:connect}}
```

</section>

Expand Down Expand Up @@ -131,7 +135,9 @@ TODO
<div slot="title">JavaScript</div>
<section>

TODO
```typescript,ignore
{{#include ../../snippets/js/src/hello.ts:publish}}
```

</section>

Expand Down Expand Up @@ -183,7 +189,9 @@ TODO
<div slot="title">JavaScript</div>
<section>

TODO
```typescript,ignore
{{#include ../../snippets/js/src/hello.ts:full}}
```

</section>

Expand Down

0 comments on commit 9be15a8

Please sign in to comment.