2023-08-03 06:40:57 +01:00
---
title: Bootstrap Nodes and Discover Peers
2023-11-23 12:01:32 +01:00
hide_table_of_contents: true
2023-08-03 06:40:57 +01:00
---
2023-11-23 12:01:32 +01:00
This guide provides detailed steps to bootstrap your your node using [Static Peers ](/learn/concepts/static-peers ) and discover peers in the Waku Network using [DNS Discovery ](/learn/concepts/dns-discovery ).
2023-08-03 06:40:57 +01:00
2023-11-30 18:42:27 +01:00
:::info
If you do not set up a bootstrap node or discovery mechanism, your node will not connect to any remote peer.
:::
2023-08-03 06:40:57 +01:00
:::tip
2023-11-23 12:01:32 +01:00
Until [node incentivisation ](/learn/research#prevention-of-denial-of-service-dos-and-node-incentivisation ) is in place, you should [operate extra nodes ](/#run-a-waku-node ) alongside the ones provided by the Waku Network. When running a node, we recommend using the [DNS Discovery and Static Peers ](#configure-dns-discovery-and-static-peers ) configuration to connect to both the Waku Network and your node.
2023-08-03 06:40:57 +01:00
:::
2023-11-23 12:01:32 +01:00
## Default bootstrap method
2023-08-03 06:40:57 +01:00
2023-11-23 12:01:32 +01:00
The `@waku/sdk` package provides a built-in bootstrapping method that uses [DNS Discovery ](/learn/concepts/dns-discovery ) to locate peers from the `waku v2.prod` `ENR` tree.
2023-08-03 06:40:57 +01:00
```js
import { createLightNode } from "@waku/sdk ";
// Bootstrap node using the default bootstrap method
const node = await createLightNode({ defaultBootstrap: true });
```
2023-11-23 12:01:32 +01:00
## Configure static peers
2023-08-03 06:40:57 +01:00
2024-03-08 05:06:21 +01:00
To set [static peers ](/learn/concepts/static-peers ), a list of `multiaddr` to bootstrap the node should be passed to the `bootstrapPeers` parameter of the `createLightNode()` function:
2023-08-03 06:40:57 +01:00
```js
import { createLightNode } from "@waku/sdk ";
// Bootstrap node using static peers
const node = await createLightNode({
2024-03-08 05:06:21 +01:00
bootstrapPeers: ["[PEER MULTIADDR]"],
2023-08-03 06:40:57 +01:00
});
```
2023-08-16 09:29:32 +01:00
For example, consider a node that connects to two static peers on the same local host (IP: `0.0.0.0` ) using TCP ports `60002` and `60003` with WebSocket enabled:
2023-08-03 06:40:57 +01:00
```js
// Define the list of static peers to bootstrap
const peers = [
2023-08-16 09:29:32 +01:00
"/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",
"/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",
2023-08-03 06:40:57 +01:00
];
// Bootstrap node using the static peers
const node = await createLightNode({
2024-03-08 05:06:21 +01:00
bootstrapPeers: peers,
2023-08-03 06:40:57 +01:00
});
```
2024-06-27 01:16:29 +02:00
Alternatively, you can dial a particular node like this:
```js
// Define the list of static peers to bootstrap
const peers = [
"/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",
"/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",
];
const node = await createLightNode();
// In case nodes are using `ws` protocol - additional configuration is needed:
/*
import { webSockets } from "@libp2p/websockets ";
import { all as filterAll } from "@libp2p/websockets/filters ";
const node = await createLightNode({
libp2p: {
transports: [webSockets({ filter: filterAll })],
},
});
*/
const promises = peers.map(multiaddr => node.dial(multiaddr));
await Promise.all(promises);
```
2023-08-16 09:29:32 +01:00
:::tip
2024-06-27 01:16:29 +02:00
For local development using a `nwaku` node, use a `ws` address instead of `wss` . Remember that this setup is functional only when your web server is running locally. You can check how to get multi address of your locally run node in [Find node address ](/guides/nwaku/find-node-address ).
2023-08-16 09:29:32 +01:00
:::
2023-11-23 12:01:32 +01:00
## Configure DNS discovery
2023-08-03 06:40:57 +01:00
2023-11-23 12:01:32 +01:00
To bootstrap a node using [DNS Discovery ](/learn/concepts/dns-discovery ), first install the `@waku/dns-discovery` package:
2023-08-03 06:40:57 +01:00
< Tabs groupId = "package-manager" >
2023-11-22 23:28:54 +01:00
< TabItem value = "npm" label = "NPM" >
2023-08-03 06:40:57 +01:00
```shell
npm install @waku/dns -discovery
```
< / TabItem >
< TabItem value = "yarn" label = "Yarn" >
```shell
yarn add @waku/dns -discovery
```
< / TabItem >
< / Tabs >
Then, use the `wakuDnsDiscovery()` function to provide a list of URLs for DNS node list in the format `enrtree://<key>@<fqdn>` :
```js
import { createLightNode } from "@waku/sdk ";
import { wakuDnsDiscovery } from "@waku/dns -discovery";
// Define DNS node list
const enrTree = "enrtree://[PUBLIC KEY]@[DOMAIN NAME]";
// Define node requirements
const NODE_REQUIREMENTS = {
store: 3,
lightPush: 3,
filter: 3,
};
// Bootstrap node using DNS Discovery
const node = await createLightNode({
libp2p: {
peerDiscovery: [
wakuDnsDiscovery(
[enrTree],
NODE_REQUIREMENTS,
),
],
},
});
```
For example, consider a node that uses the `waku v2.prod` and `waku v2.test` `ENR` trees for `DNS Discovery` :
```js
import { enrTree } from "@waku/dns -discovery";
// Bootstrap node using DNS Discovery
const node = await createLightNode({
libp2p: {
peerDiscovery: [
wakuDnsDiscovery(
[enrTree["PROD"], enrTree["TEST"]],
NODE_REQUIREMENTS,
),
],
},
});
```
2023-11-23 12:01:32 +01:00
## Configure DNS discovery and static peers
2023-08-03 06:40:57 +01:00
2023-11-23 12:01:32 +01:00
You can also bootstrap your node using [DNS Discovery ](/learn/concepts/dns-discovery ) and [Static Peers ](/learn/concepts/static-peers ) simultaneously:
2023-08-03 06:40:57 +01:00
```js
import { createLightNode } from "@waku/sdk ";
import { bootstrap } from "@libp2p/bootstrap ";
import { enrTree, wakuDnsDiscovery } from "@waku/dns -discovery";
// Define the list of static peers to bootstrap
const peers = [
2023-08-16 09:29:32 +01:00
"/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",
"/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",
2023-08-03 06:40:57 +01:00
];
// Define node requirements
const NODE_REQUIREMENTS = {
store: 3,
lightPush: 3,
filter: 3,
};
2024-03-08 05:06:21 +01:00
// Bootstrap node using DNS Discovery and static peers
2023-08-03 06:40:57 +01:00
const node = await createLightNode({
libp2p: {
2024-03-08 05:06:21 +01:00
bootstrapPeers: peers,
2023-08-03 06:40:57 +01:00
peerDiscovery: [
wakuDnsDiscovery(
[enrTree["PROD"]],
NODE_REQUIREMENTS,
),
],
},
});
```
2023-11-30 18:42:27 +01:00
## Retrieving connected peers
You can retrieve the array of peers connected to a node using the `libp2p.getPeers()` function within the `@waku/sdk` package:
```js
import { createLightNode, waitForRemotePeer } from "@waku/sdk ";
const node = await createLightNode({ defaultBootstrap: true });
await waitForRemotePeer(node);
// Retrieve array of peers connected to the node
console.log(node.libp2p.getPeers());
```