πWaku Node
π What is Waku?
Waku is a protocol enabling peer-to-peer messaging with privacy-preserving features. It's built to be lightweight and scalable, making it suitable for decentralized applications (dApps). It leverages the principles of the Whisper protocol but adds enhancements for reliability and scalability.
ποΈ Overview of the Repository
The repository organizes resources into categories:
Waku Clients: Implementations of the Waku protocol (e.g., Go-Waku, JS-Waku).
Libraries: Tools to simplify Waku integration.
Specifications: Protocol definitions and Waku's interaction layers.
Tutorials: Guides for getting started with Waku.
π Getting Started with Waku
Prerequisites
Ensure you have Node.js and npm installed (for JS projects).
Install Docker if you want to run a Waku node locally.
1. Setting Up a Waku Node
You can use Go-Waku, a Go implementation of the Waku protocol, to run a local node.
Using Docker
Run the following command to start a Waku node with Docker:
docker run -p 60000:60000/udp -p 60000:60000/tcp -p 8545:8545 \
statusteam/nim-waku
This starts a node that listens for messages on ports 60000
(TCP/UDP) and exposes an API on port 8545
.
Installing Go-Waku Locally
Alternatively, install Go-Waku locally by following the Go-Waku documentation.
2. Integrating JS-Waku into Your dApp
JS-Waku is a JavaScript library for interacting with the Waku network. Hereβs how to use it in your project.
Installation
Run the following command to install the library:
npm install js-waku
Sending and Receiving Messages
import { Waku } from "js-waku";
// Initialize a Waku instance
async function startWaku() {
const waku = await Waku.create({
bootstrap: true, // Connects to public nodes
});
console.log("Waku initialized");
// Sending a message
const contentTopic = "/example/topic";
const payload = new TextEncoder().encode("Hello, Waku!");
await waku.relay.send(contentTopic, payload);
console.log("Message sent");
// Receiving messages
waku.relay.subscribe([contentTopic], (message) => {
console.log("Received message:", new TextDecoder().decode(message.payload));
});
return waku;
}
startWaku();
3. Using Waku for Decentralized Chat
Create a basic chat app using Waku.
Frontend Code
import { Waku } from "js-waku";
let waku;
const contentTopic = "/chat/example";
async function initializeWaku() {
waku = await Waku.create({ bootstrap: true });
console.log("Waku initialized");
waku.relay.subscribe([contentTopic], (msg) => {
const text = new TextDecoder().decode(msg.payload);
displayMessage(text, "peer");
});
}
function sendMessage() {
const input = document.getElementById("messageInput");
const message = input.value;
input.value = "";
const payload = new TextEncoder().encode(message);
waku.relay.send(contentTopic, payload);
displayMessage(message, "self");
}
function displayMessage(message, sender) {
const chat = document.getElementById("chat");
const newMessage = document.createElement("div");
newMessage.textContent = `${sender}: ${message}`;
chat.appendChild(newMessage);
}
document.getElementById("sendButton").addEventListener("click", sendMessage);
initializeWaku();
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Waku Chat</title>
</head>
<body>
<div id="chat" style="height: 200px; overflow-y: auto; border: 1px solid black;"></div>
<input id="messageInput" type="text" placeholder="Type a message..." />
<button id="sendButton">Send</button>
<script src="./chat.js"></script>
</body>
</html>
4. Exploring Specifications
If you're developing a custom implementation, review the Waku Specifications for detailed protocol behavior.
π οΈ Contributing
You can contribute to the Awesome Waku repository by:
Submitting useful tools or libraries.
Writing tutorials.
Reporting issues or improvements for the list.
Fork the repository, make your changes, and submit a pull request following their contributing guidelines.
π Resources
Happy coding! π
Last updated