Skip to content

Commit 3098b18

Browse files
authored
Add Local network (#5)
* add local network option * improve README
1 parent 6b1e265 commit 3098b18

3 files changed

Lines changed: 51 additions & 8 deletions

File tree

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pnpm install
1616
## Environment variables
1717

1818
Required:
19-
- `NETWORK` (`testnet` or `stagenet`)
19+
- `NETWORK` (`testnet`, `stagenet` or `local`)
2020

2121
Optional:
2222
- none (health checks are unauthenticated)
@@ -26,6 +26,17 @@ Optional:
2626
Network URLs/IDs are intentionally **hardcoded** in `src/networks.ts` and are copied from `datahaven-monitor`:
2727
- **Testnet**: MSP `https://deo-dh-backend.testnet.datahaven-infra.network`
2828
- **Stagenet**: MSP `https://deo-dh-backend.stagenet.datahaven-infra.network`
29+
- **Local**: MSP `http://127.0.0.1:8080`, RPC `http://127.0.0.1:9888`
30+
31+
Local notes:
32+
- `NETWORK=local` matches the “normal” local StorageHub defaults when you boot a local network from the StorageHub repo with:
33+
- `pnpm docker:start:solochain-evm:initialised`
34+
- See StorageHub docs: [Spawning solochain-evm-initialised fullnet](https://github.com/Moonsong-Labs/storage-hub/tree/main/test#spawning-solochain-evm-initialised-fullnet)
35+
- It assumes:
36+
- MSP at `http://127.0.0.1:8080`
37+
- EVM/Substrate RPC at `http://127.0.0.1:9888` / `ws://127.0.0.1:9888`
38+
- **SIWE domain/uri**: these should be provided by the dApp doing SIWE (they are not “network” properties). For local testing, a dApp often runs on `localhost:3000` or `localhost:3001`.
39+
- `localhost:3001` / `http://localhost:3001` is what the StorageHub repo’s `demo-app` (SDK examples) commonly uses.
2940

3041
## Commands
3142

@@ -37,6 +48,16 @@ Network URLs/IDs are intentionally **hardcoded** in `src/networks.ts` and are co
3748
- `pnpm test:msp-unauth` — standalone unauth MSP load test (no SIWE, no keys)
3849
- `pnpm test:download` — file download load test (requires SIWE auth + FILE_KEY)
3950

51+
Examples (local):
52+
53+
```bash
54+
NETWORK=local pnpm test:msp-unauth
55+
```
56+
57+
```bash
58+
NETWORK=local STORAGEHUB_PRIVATE_KEY=0x... pnpm test
59+
```
60+
4061
## Logging
4162

4263
Logging is handled by **Pino**.

src/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type Env = Readonly<{
2-
network: "testnet" | "stagenet";
2+
network: "testnet" | "stagenet" | "local";
33
}>;
44

55
function getRequiredEnv(key: string): string {
@@ -12,9 +12,13 @@ function getRequiredEnv(key: string): string {
1212

1313
export function readEnv(): Env {
1414
const networkRaw = getRequiredEnv("NETWORK");
15-
if (networkRaw !== "testnet" && networkRaw !== "stagenet") {
15+
if (
16+
networkRaw !== "testnet" &&
17+
networkRaw !== "stagenet" &&
18+
networkRaw !== "local"
19+
) {
1620
throw new Error(
17-
`Invalid NETWORK: ${networkRaw} (expected 'testnet' or 'stagenet')`
21+
`Invalid NETWORK: ${networkRaw} (expected 'testnet', 'stagenet' or 'local')`
1822
);
1923
}
2024
const network = networkRaw;

src/networks.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export type NetworkName = "testnet" | "stagenet";
1+
export type NetworkName = "testnet" | "stagenet" | "local";
22

33
export type NetworkConfig = Readonly<{
44
name: NetworkName;
55
chain: Readonly<{
66
id: number;
77
name: string;
88
evmRpcUrl: string;
9-
substrateWsUrl: `wss://${string}`;
9+
substrateWsUrl: `${"ws" | "wss"}://${string}`;
1010
filesystemPrecompileAddress: `0x${string}`;
1111
}>;
1212
msp: Readonly<{
@@ -53,11 +53,29 @@ export const NETWORKS: Readonly<Record<NetworkName, NetworkConfig>> = {
5353
siweUri: "https://deo-dh-backend.stagenet.datahaven-infra.network",
5454
},
5555
},
56+
local: {
57+
name: "local",
58+
chain: {
59+
id: 181222,
60+
name: "StorageHub Solochain EVM",
61+
evmRpcUrl: "http://127.0.0.1:9888",
62+
substrateWsUrl: "ws://127.0.0.1:9888",
63+
filesystemPrecompileAddress: "0x0000000000000000000000000000000000000064",
64+
},
65+
msp: {
66+
baseUrl: "http://127.0.0.1:8080",
67+
timeoutMs: 60_000,
68+
siweDomain: "localhost:3001",
69+
siweUri: "http://localhost:3001",
70+
},
71+
},
5672
} as const;
5773

5874
export function parseNetworkName(raw: string): NetworkName {
59-
if (raw === "testnet" || raw === "stagenet") {
75+
if (raw === "testnet" || raw === "stagenet" || raw === "local") {
6076
return raw;
6177
}
62-
throw new Error(`Invalid NETWORK: ${raw} (expected 'testnet' or 'stagenet')`);
78+
throw new Error(
79+
`Invalid NETWORK: ${raw} (expected 'testnet', 'stagenet' or 'local')`
80+
);
6381
}

0 commit comments

Comments
 (0)