Skip to content

Commit

Permalink
feat: add node and webpack to workers (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Oliva <[email protected]>
Co-authored-by: Carlo Sala <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent b308edb commit 6d59f10
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int

<Tabs.Root options={{
smw: 'Smoldot (WebWorker)',
smnw: 'Smoldot (NodeJS WebWorker)',
sm: 'Smoldot',
web: 'WebSocket',
node: 'NodeJS Socket',
Expand All @@ -37,9 +38,17 @@ Now you can create a PolkadotClient with a provider of your choice and start int
import { getSmProvider } from "polkadot-api/sm-provider";
import { chainSpec } from "polkadot-api/chains/polkadot";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";

// Using vite
import SmWorker from "polkadot-api/smoldot/worker?worker";
const worker = new SmWorker();

// Using Webpack
// const worker = new Worker(
// new URL("polkadot-api/smoldot/worker", import.meta.url)
// );

const smoldot = startFromWorker(new SmWorker());
const smoldot = startFromWorker(worker);
const chain = await smoldot.addChain({ chainSpec });

// Connect to the polkadot relay chain.
Expand All @@ -49,7 +58,33 @@ Now you can create a PolkadotClient with a provider of your choice and start int

// [!include ~/snippets/gettingStarted.ts:usage]
```
</Tabs.Content>
<Tabs.Content value="snmw">
```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]
```
</Tabs.Content>
<Tabs.Content value="sm">
```ts
Expand Down

0 comments on commit 6d59f10

Please sign in to comment.