From 667edf0129b0807517b4e581d3eb64fa7ce05cce Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Sat, 11 Mar 2023 19:31:38 +1100 Subject: [PATCH] fix: Update docs showing how to use ESM instead of CommonJS and WS to connect to local node --- docs/build/sdk/v2/getting-started.md | 19 ++++++++++++++++++- docs/build/sdk/v2/market-creation-two-step.md | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/build/sdk/v2/getting-started.md b/docs/build/sdk/v2/getting-started.md index 34cd3e72..d93d039f 100644 --- a/docs/build/sdk/v2/getting-started.md +++ b/docs/build/sdk/v2/getting-started.md @@ -34,6 +34,17 @@ a more optimized way and also need to interact with the chain itself. ::: +:::info + +If you are trying to import dependencies using CommonJS `require("")` syntax with `const { create, mainnet } = require("@zeitgeistpm/sdk")`, then it will not work. Instead you need to import with Modules (ESM) `await import("")` syntax. For example: +```js +(async () => { + const { create, mainnet } = await import("@zeitgeistpm/sdk")` +})().catch(console.error).finally(() => process.exit()); +``` + +::: + ### Rpc Mode The rpc mode connects only to the rpc chain node and has a bit more limitations @@ -141,7 +152,7 @@ import { create, createStorage } from "@zeitgeistpm/sdk"; import { IPFS } from "@zeitgeistpm/web3.storage"; const sdk: Sdk = await create({ - provider: "wss://localhost:9944", + provider: "ws://localhost:9944", storage: createStorage( IPFS.storage({ node: { url: "localhost:5001" }, @@ -149,3 +160,9 @@ const sdk: Sdk = await create({ ), }); ``` + +:::note + +In production you are recommended to use `wss` (WebSocket Secure) instead of `ws` + +::: diff --git a/docs/build/sdk/v2/market-creation-two-step.md b/docs/build/sdk/v2/market-creation-two-step.md index c8cd0ec6..1fdf8386 100644 --- a/docs/build/sdk/v2/market-creation-two-step.md +++ b/docs/build/sdk/v2/market-creation-two-step.md @@ -24,7 +24,7 @@ import { } from "@zeitgeistpm/sdk"; /** - * Initialize the SDK in full or rpc mode to be able to submit transactions to the chein. + * Initialize the SDK in full or rpc mode to be able to submit transactions to the chain. */ const sdk: Sdk = await create(batterystationRpc());