This commit is contained in:
LordGhostX 2024-05-13 14:43:25 +01:00
parent ff5464b7d3
commit acb0a75d55
No known key found for this signature in database
GPG Key ID: 520CC5DC4F94FCC7

View File

@ -24,6 +24,8 @@ await node.start();
When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes.
::: :::
Your node will route messages to the default pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can change this using the `ShardInfo` parameter:
## Connect to remote peers ## Connect to remote peers
Use the `waitForRemotePeer()` function to wait for the node to connect with peers on the Waku Network: Use the `waitForRemotePeer()` function to wait for the node to connect with peers on the Waku Network:
@ -41,10 +43,7 @@ The `protocols` parameter allows you to specify the [protocols](/learn/concepts/
import { waitForRemotePeer, Protocols } from "@waku/sdk"; import { waitForRemotePeer, Protocols } from "@waku/sdk";
// Wait for peer connections with specific protocols // Wait for peer connections with specific protocols
await waitForRemotePeer(node, [ await waitForRemotePeer(node, [Protocols.LightPush, Protocols.Filter]);
Protocols.LightPush,
Protocols.Filter,
]);
``` ```
## Choose a content topic ## Choose a content topic
@ -66,8 +65,8 @@ The `ephemeral` parameter allows you to specify whether messages should **NOT**
```js ```js
const encoder = createEncoder({ const encoder = createEncoder({
contentTopic: contentTopic, // message content topic contentTopic: contentTopic, // message content topic
ephemeral: true, // allows messages NOT be stored on the network ephemeral: true, // allows messages NOT be stored on the network
}); });
``` ```
@ -84,9 +83,9 @@ import protobuf from "protobufjs";
// Create a message structure using Protobuf // Create a message structure using Protobuf
const ChatMessage = new protobuf.Type("ChatMessage") const ChatMessage = new protobuf.Type("ChatMessage")
.add(new protobuf.Field("timestamp", 1, "uint64")) .add(new protobuf.Field("timestamp", 1, "uint64"))
.add(new protobuf.Field("sender", 2, "string")) .add(new protobuf.Field("sender", 2, "string"))
.add(new protobuf.Field("message", 3, "string")); .add(new protobuf.Field("message", 3, "string"));
``` ```
:::info :::info
@ -100,9 +99,9 @@ To send messages over the Waku Network using the `Light Push` protocol, create a
```js ```js
// Create a new message object // Create a new message object
const protoMessage = ChatMessage.create({ const protoMessage = ChatMessage.create({
timestamp: Date.now(), timestamp: Date.now(),
sender: "Alice", sender: "Alice",
message: "Hello, World!", message: "Hello, World!",
}); });
// Serialise the message using Protobuf // Serialise the message using Protobuf
@ -110,7 +109,7 @@ const serialisedMessage = ChatMessage.encode(protoMessage).finish();
// Send the message using Light Push // Send the message using Light Push
await node.lightPush.send(encoder, { await node.lightPush.send(encoder, {
payload: serialisedMessage, payload: serialisedMessage,
}); });
``` ```
@ -121,11 +120,11 @@ To receive messages using the `Filter` protocol, create a callback function for
```js ```js
// Create the callback function // Create the callback function
const callback = (wakuMessage) => { const callback = (wakuMessage) => {
// Check if there is a payload on the message // Check if there is a payload on the message
if (!wakuMessage.payload) return; if (!wakuMessage.payload) return;
// Render the messageObj as desired in your application // Render the messageObj as desired in your application
const messageObj = ChatMessage.decode(wakuMessage.payload); const messageObj = ChatMessage.decode(wakuMessage.payload);
console.log(messageObj); console.log(messageObj);
}; };
// Create a Filter subscription // Create a Filter subscription