Skip to content
34 changes: 34 additions & 0 deletions examples/smoldot_read.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkontur I think it's a good practice to keep one package.json. I added package.json to one of ahm-dryrun subfolders and @seadanda suggested to stick to one package.json because:

  • multiple package.json files may easily go out of sync and cause a "dependency drift",
  • tools like tsconfig, jest, etc need to know which workspace they’re running in. Multiple package.json can lead to configs not being picked up correctly, working in one folder but not another.

Let's maybe revert back to a single package.json?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea a single top level file was preferable for ahm-dryrun because we wanted to keep packages in sync and used the same frameworks etc everywhere, but sometimes you don't actually want that, and multiple package.jsons are fine (there are even some tools to manage that flow like npm workspaces/turborepo).

There are legit usecases for each, but I think that the simplest is best unless you need multiple

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe revert back to a single package.json?

But we have just one examples/package.json.

Point of these examples is to use the same versions as simply as possible and run them as a part of CI. I don't see any reason to have multiple package.json and versions.

Copy link
Contributor Author

@x3c41a x3c41a Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an old comment, it concerned the state of this PR (or related) when we had two package.json, now we have only one so it's already obsolete, I believe.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as smoldot from 'smoldot';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { ApiPromise, WsProvider } from '@polkadot/api';


async function main() {
await cryptoWaitReady();

// Download the raw chain spec from an RPC node.
// Note: The dApps or the actual application should not connect to any external RPC node,
// but should instead use chain specs provided directly.
// 12346 is Bob's validator rpc port, because Alice does not have `bootNodes`.
const ws = new WsProvider('ws://localhost:12346');
const api = await ApiPromise.create({ provider: ws });
await api.isReady;
const chainSpec = await api.rpc.syncstate.genSyncSpec(true);

const client = smoldot.start();

await client
.addChain({ chainSpec: chainSpec.toString() })
.then((chain) => {
chain.sendJsonRpc(`{"jsonrpc":"2.0","id":12,"method":"chain_getFinalizedHead","params":[]}`);
return chain;
})
.then(async (chain) => {
const response = await chain.nextJsonRpcResponse();
console.log("✅ JSON-RPC response:", response);
return chain;
})
.then(() => client.terminate());
}

await main();