From 6d59f109b3d5de25b270b97354142c94c82d9bf4 Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Mon, 5 Aug 2024 11:03:31 +0200 Subject: [PATCH] feat: add node and webpack to workers (#15) Co-authored-by: Victor Oliva Co-authored-by: Carlo Sala --- docs/pages/getting-started.mdx | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/pages/getting-started.mdx b/docs/pages/getting-started.mdx index a69c341f..2eea8323 100644 --- a/docs/pages/getting-started.mdx +++ b/docs/pages/getting-started.mdx @@ -27,6 +27,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int + + ```ts + // [!include ~/snippets/gettingStarted.ts:import] + import { getSmProvider } from "polkadot-api/sm-provider"; + import { chainSpec } from "polkadot-api/chains/polkadot"; + import { startFromWorker } from "polkadot-api/smoldot/from-node-worker"; + import { fileURLToPath } from "url" + import { Worker } from "worker_threads" + + const workerPath = fileURLToPath( + import.meta.resolve("polkadot-api/smoldot/node-worker") + ); + // Or with cjs + // const workerPath = require.resolve("polkadot-api/smoldot/node-worker"); + const worker = new Worker(workerPath); + const smoldot = startFromWorker(worker); + const chain = await smoldot.addChain({ chainSpec }); + + // Connect to the polkadot relay chain. + const client = createClient( + getSmProvider(chain) + ); + + // [!include ~/snippets/gettingStarted.ts:usage] + ``` ```ts