From c74a8808386ac2aadac64d3df24cf680fa5ba9a0 Mon Sep 17 00:00:00 2001 From: Mark Sinclair Date: Mon, 14 Nov 2022 15:58:00 +0000 Subject: [PATCH] Update README for SDK --- sdk/typescript/packages/sdk/README.md | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/sdk/typescript/packages/sdk/README.md b/sdk/typescript/packages/sdk/README.md index c1f1fc5a7f..e5f2fd51c5 100644 --- a/sdk/typescript/packages/sdk/README.md +++ b/sdk/typescript/packages/sdk/README.md @@ -13,9 +13,30 @@ npm install @nymproject/sdk Open a connection to a Gateway on the Nym Mixnet: ```ts -import { client } from '@nymproject/sdk'; +import { createNymMixnetClient } from '@nymproject/sdk'; -const session = await client.connect('<>'); +const main = async () => { + const nym = await createNymMixnetClient(); + + const validatorApiUrl = 'https://validator.nymtech.net/api'; + + // show message payload content when received + nym.events.subscribeToTextMessageReceivedEvent((e) => { + console.log('Got a message: ', e.args.payload); + }); + + // start the client and connect to a gateway + await nym.client.start({ + clientId: 'My awesome client', + validatorApiUrl, + }); + + // send a message to yourself + const payload = 'Hello mixnet'; + const recipient = nym.client.selfAddress(); + nym.client.sendMessage({ payload, recipient }); + +}; ``` This will start the WASM client on a worker thread, so that your code can stay nice and snappy. @@ -23,7 +44,9 @@ This will start the WASM client on a worker thread, so that your code can stay n Send a message to another user (you will need to know their address at a Gateway): ```ts -const result = await client.send('<>', 'Hello Timmy!'); + const payload = 'Hello mixnet'; + const recipient = '<< RECIPIENT ADDRESS GOES HERE >>'; + await nym.client.sendMessage({ payload, recipient }); ``` ### Packaging