docs.waku.org/docs/guides/js-waku/index.md

4.9 KiB

title
JavaScript Waku SDK

The JavaScript Waku SDK (@waku/sdk) provides a TypeScript implementation of the Waku protocol designed for web browser environments. Developers can seamlessly integrate Waku functionalities into web applications, enabling efficient communication and collaboration among users using the @waku/sdk package.

Installation

Install the @waku/sdk package using your preferred package manager:

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
npm install @waku/sdk
yarn add @waku/sdk

You can also use the @waku/sdk package via a CDN without installing it on your system:

import * as waku from "https://unpkg.com/@waku/sdk@latest/bundle/index.js";

Message Structure

We recommend creating a message structure for your application using Protocol Buffers for the following reasons:

  1. Consistency: Ensures uniform message format for easy parsing and processing.
  2. Interoperability: Facilitates effective communication between different parts of your application.
  3. Compatibility: Allows smooth communication between older and newer app versions.
  4. Payload Size: Minimizes payload overhead, especially for byte arrays, unlike JSON which adds significant overhead.

To get started, install the protobufjs package using your preferred package manager:

npm install protobufjs
yarn add protobufjs

You can also use the protobufjs package via a CDN without installing it on your system:

// Import the CDN
import "https://cdn.jsdelivr.net/npm/protobufjs@latest/dist/protobuf.min.js";
<!-- Or include the protobufjs script -->
<script src="https://cdn.jsdelivr.net/npm/protobufjs@latest/dist/protobuf.min.js"></script>

Getting Started

Have a look at the quick start guide and comprehensive tutorials to learn how to build applications using @waku/sdk:

Guide Description
Send and Receive Messages Using Light Push and Filter Learn how to send and receive messages on light nodes using the Light Push and Filter protocols
Retrieve Messages Using Store Protocol Learn how to retrieve and filter historical messages on light nodes using the Store protocol
Bootstrap DApps Using @waku/create-app Learn how to use the @waku/create-app package to bootstrap your next @waku/sdk project from various example templates
Bootstrap Nodes and Discover Peers Learn how to bootstrap your node using Static Peers and discover peers using DNS Discovery
Run @waku/sdk in a NodeJS Application Learn our suggested approach for using the @waku/sdk package within a NodeJS application
How to Debug Your Waku DApp and WebSocket Learn how to troubleshoot your Waku DApp using debug logs and check WebSocket connections in nwaku

:::tip Until node incentivisation is in place, you should operate extra nodes alongside the ones provided by the Waku Network. When running a node, we recommend using the DNS Discovery and Static Peers configuration to connect to both the Waku Network and your node. :::

Get Help and Report Issues

To engage in general discussions, seek assistance, or stay updated with the latest news, visit the #support and #js-waku-contribute channels on the Waku Discord.

If you discover bugs or want to suggest new features, do not hesitate to open an issue in the js-waku repository. Your feedback and contributions are highly valued and will help improve the @waku/sdk package.