diff --git a/book/snippets/js/src/hello.ts b/book/snippets/js/src/hello.ts new file mode 100644 index 000000000..b0cc534d2 --- /dev/null +++ b/book/snippets/js/src/hello.ts @@ -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 diff --git a/book/src/sdk/hello.md b/book/src/sdk/hello.md index 4410b10b9..184711119 100644 --- a/book/src/sdk/hello.md +++ b/book/src/sdk/hello.md @@ -26,7 +26,9 @@ Now that you’ve installed the SDK, it’s time to write your first nostr progr
JavaScript
-TODO +```typescript,ignore +{{#include ../../snippets/js/src/hello.ts:client}} +```
@@ -78,7 +80,9 @@ TODO
JavaScript
-TODO +```typescript,ignore +{{#include ../../snippets/js/src/hello.ts:connect}} +```
@@ -131,7 +135,9 @@ TODO
JavaScript
-TODO +```typescript,ignore +{{#include ../../snippets/js/src/hello.ts:publish}} +```
@@ -183,7 +189,9 @@ TODO
JavaScript
-TODO +```typescript,ignore +{{#include ../../snippets/js/src/hello.ts:full}} +```