|
| 1 | +--- |
| 2 | +title: Set Up a Local Development Environment |
| 3 | +--- |
| 4 | + |
| 5 | +# Set Up a Local Development Environment |
| 6 | + |
| 7 | +The most reliable way to ensure your js-waku application will work in realistic conditions is to spin up a local nwaku fleet and test against it. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +- [Docker Desktop](https://www.docker.com/products/docker-desktop/) or Docker Engine with Compose plugin |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### 1. Start the Network |
| 16 | + |
| 17 | +```bash |
| 18 | +npx @waku/run start |
| 19 | +``` |
| 20 | + |
| 21 | +This will: |
| 22 | +- Start 2 nwaku nodes and a PostgreSQL database |
| 23 | +- Run in the background (detached mode) |
| 24 | +- Display connection information you need for your app |
| 25 | + |
| 26 | +**Example output:** |
| 27 | +```typescript |
| 28 | +import { createLightNode } from "@waku/sdk"; |
| 29 | + |
| 30 | +const waku = await createLightNode({ |
| 31 | + defaultBootstrap: false, |
| 32 | + bootstrapPeers: [ |
| 33 | + "/ip4/127.0.0.1/tcp/60000/ws/p2p/16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2", |
| 34 | + "/ip4/127.0.0.1/tcp/60001/ws/p2p/16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ" |
| 35 | + ], |
| 36 | + numPeersToUse: 2, |
| 37 | + libp2p: { |
| 38 | + filterMultiaddrs: false |
| 39 | + }, |
| 40 | + networkConfig: { |
| 41 | + clusterId: 0, |
| 42 | + numShardsInCluster: 8 |
| 43 | + } |
| 44 | +}); |
| 45 | +``` |
| 46 | + |
| 47 | +### 2. Connect Your js-waku App |
| 48 | + |
| 49 | +Copy the configuration from the output above and paste it into your application. Then start your node: |
| 50 | + |
| 51 | +```typescript |
| 52 | +await waku.start(); |
| 53 | + |
| 54 | +// Your app is now connected to your local Waku network! |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. Stop When Done |
| 58 | + |
| 59 | +```bash |
| 60 | +npx @waku/run stop |
| 61 | +``` |
| 62 | + |
| 63 | +## Available Commands |
| 64 | + |
| 65 | +### Using npx (published package) |
| 66 | + |
| 67 | +| Command | Description | |
| 68 | +|---------|-------------| |
| 69 | +| `npx @waku/run start` | Start the network (detached) and show connection info | |
| 70 | +| `npx @waku/run stop` | Stop the network and clean up | |
| 71 | +| `npx @waku/run info` | Show connection info for running network | |
| 72 | +| `npx @waku/run logs` | View and follow logs from all nodes | |
| 73 | +| `npx @waku/run test` | Test the network by sending a message | |
| 74 | + |
| 75 | +## Configuration |
| 76 | + |
| 77 | +All configuration is done via environment variables passed to the command. |
| 78 | + |
| 79 | +### Custom Ports |
| 80 | + |
| 81 | +If the default ports are in use, specify custom ports: |
| 82 | + |
| 83 | +```bash |
| 84 | +NODE1_WS_PORT=50000 NODE2_WS_PORT=50001 npx @waku/run start |
| 85 | +``` |
| 86 | + |
| 87 | +Available port configuration: |
| 88 | +- `NODE1_WS_PORT` (default: 60000) |
| 89 | +- `NODE2_WS_PORT` (default: 60001) |
| 90 | +- `NODE1_REST_PORT` (default: 8646) |
| 91 | +- `NODE2_REST_PORT` (default: 8647) |
| 92 | + |
| 93 | +### Cluster Configuration |
| 94 | + |
| 95 | +The default configuration uses: |
| 96 | +- Cluster ID: 0 |
| 97 | +- Number of shards: 8 |
| 98 | + |
| 99 | +To test with a different cluster: |
| 100 | + |
| 101 | +```bash |
| 102 | +CLUSTER_ID=16 npx @waku/run start |
| 103 | +``` |
| 104 | + |
| 105 | +### Custom nwaku Version |
| 106 | + |
| 107 | +To use a different nwaku image version: |
| 108 | + |
| 109 | +```bash |
| 110 | +NWAKU_IMAGE=wakuorg/nwaku:v0.35.0 npx @waku/run start |
| 111 | +``` |
| 112 | + |
| 113 | +## Debugging |
| 114 | + |
| 115 | +### View Node Logs |
| 116 | + |
| 117 | +```bash |
| 118 | +npx @waku/run logs |
| 119 | +``` |
| 120 | + |
| 121 | +### Check Node Health |
| 122 | + |
| 123 | +```bash |
| 124 | +# Node 1 |
| 125 | +curl http://127.0.0.1:8646/health |
| 126 | + |
| 127 | +# Node 2 |
| 128 | +curl http://127.0.0.1:8647/health |
| 129 | +``` |
| 130 | + |
| 131 | +### Check Peer Connections |
| 132 | + |
| 133 | +```bash |
| 134 | +# Node 1 debug info |
| 135 | +curl http://127.0.0.1:8646/debug/v1/info |
| 136 | + |
| 137 | +# Node 2 debug info |
| 138 | +curl http://127.0.0.1:8647/debug/v1/info |
| 139 | +``` |
0 commit comments