|
| 1 | +--- |
| 2 | +title: JavaScript Waku SDK |
| 3 | +hide_table_of_contents: true |
| 4 | +displayed_sidebar: build |
| 5 | +--- |
| 6 | + |
| 7 | +:::caution |
| 8 | +Currently, the JavaScript Waku SDK (`@waku/sdk`) is **NOT compatible** with React Native. We plan to add support for React Native in the future. |
| 9 | +::: |
| 10 | + |
| 11 | +The [JavaScript Waku SDK](https://github.com/waku-org/js-waku) (`@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. |
| 12 | + |
| 13 | +## Video Tutorials |
| 14 | + |
| 15 | +<div class="video-container"> |
| 16 | + <iframe class="yt-video two-items" src="https://www.youtube.com/embed/PYQaXCxUCwA" title="Waku Tutorial 001: Introduction to Waku" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 17 | + |
| 18 | +<iframe class="yt-video two-items" src="https://www.youtube.com/embed/sfmMcrbiX0c" title="Build a game using Waku Protocol" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 19 | +</div> |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +Install the `@waku/sdk` package using your preferred package manager: |
| 24 | + |
| 25 | +```mdx-code-block |
| 26 | +import Tabs from '@theme/Tabs'; |
| 27 | +import TabItem from '@theme/TabItem'; |
| 28 | +``` |
| 29 | + |
| 30 | +<Tabs groupId="package-manager"> |
| 31 | +<TabItem value="npm" label="NPM"> |
| 32 | + |
| 33 | +```shell |
| 34 | +npm install @waku/sdk |
| 35 | +``` |
| 36 | + |
| 37 | +</TabItem> |
| 38 | +<TabItem value="yarn" label="Yarn"> |
| 39 | + |
| 40 | +```shell |
| 41 | +yarn add @waku/sdk |
| 42 | +``` |
| 43 | + |
| 44 | +</TabItem> |
| 45 | +</Tabs> |
| 46 | + |
| 47 | +You can also use the `@waku/sdk` package via a CDN without installing it on your system: |
| 48 | + |
| 49 | +```js |
| 50 | +import * as waku from "https://unpkg.com/@waku/sdk@latest/bundle/index.js"; |
| 51 | +``` |
| 52 | + |
| 53 | +## Message structure |
| 54 | + |
| 55 | +We recommend creating a message structure for your application using [Protocol Buffers](https://protobuf.dev/) for the following reasons: |
| 56 | + |
| 57 | +1. **Consistency:** Ensures uniform message format for easy parsing and processing. |
| 58 | +2. **Interoperability:** Facilitates effective communication between different parts of your application. |
| 59 | +3. **Compatibility:** Allows smooth communication between older and newer app versions. |
| 60 | +4. **Payload Size:** Minimizes payload overhead, especially for byte arrays, unlike JSON which adds significant overhead. |
| 61 | + |
| 62 | +To get started, install the `protobufjs` package using your preferred package manager: |
| 63 | + |
| 64 | +<Tabs groupId="package-manager"> |
| 65 | +<TabItem value="npm" label="NPM"> |
| 66 | + |
| 67 | +```shell |
| 68 | +npm install protobufjs |
| 69 | +``` |
| 70 | + |
| 71 | +</TabItem> |
| 72 | +<TabItem value="yarn" label="Yarn"> |
| 73 | + |
| 74 | +```shell |
| 75 | +yarn add protobufjs |
| 76 | +``` |
| 77 | + |
| 78 | +</TabItem> |
| 79 | +</Tabs> |
| 80 | + |
| 81 | +You can also use the `protobufjs` package via a CDN without installing it on your system: |
| 82 | + |
| 83 | +```js |
| 84 | +// Import the CDN |
| 85 | +import "https://cdn.jsdelivr.net/npm/protobufjs@latest/dist/protobuf.min.js"; |
| 86 | +``` |
| 87 | + |
| 88 | +```html |
| 89 | +<!-- Or include the protobufjs script --> |
| 90 | +<script src="https://cdn.jsdelivr.net/npm/protobufjs@latest/dist/protobuf.min.js"></script> |
| 91 | +``` |
| 92 | + |
| 93 | +## Getting started |
| 94 | + |
| 95 | +Have a look at the quick start guide and comprehensive tutorials to learn how to build applications using `@waku/sdk`: |
| 96 | + |
| 97 | +| Guide | Description | |
| 98 | +|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 99 | +| [Send and Receive Messages in a Reliable Channel](/build/javascript/reliable-channels) | Learn how to send and receive messages with a convenient SDK that provide various reliable functionalities out-of-the-box. | |
| 100 | +| [Send and Receive Messages Using Light Push and Filter](/build/javascript/light-send-receive) | Learn how to send and receive messages on light nodes using the [Light Push](/learn/concepts/protocols#light-push) and [Filter](/learn/concepts/protocols#filter) protocols | |
| 101 | +| [Retrieve Messages Using Store Protocol](/build/javascript/store-retrieve-messages) | Learn how to retrieve and filter historical messages on light nodes using the [Store protocol](/learn/concepts/protocols#store) | |
| 102 | +| [Encrypt, Decrypt, and Sign Your Messages](/build/javascript/message-encryption) | Learn how to use the [@waku/message-encryption](https://www.npmjs.com/package/@waku/message-encryption) package to encrypt, decrypt, and sign your messages | |
| 103 | +| [Build React DApps Using @waku/react](/build/javascript/use-waku-react) | Learn how to use the [@waku/react](https://www.npmjs.com/package/@waku/react) package seamlessly integrate `@waku/sdk` into a React application | |
| 104 | +| [Scaffold DApps Using @waku/create-app](/build/javascript/use-waku-create-app) | Learn how to use the [@waku/create-app](https://www.npmjs.com/package/@waku/create-app) package to bootstrap your next `@waku/sdk` project from various example templates | |
| 105 | +| [Bootstrap Nodes and Discover Peers](/build/javascript/configure-discovery) | Learn how to bootstrap your node using [Static Peers](/learn/concepts/static-peers) and discover peers using [DNS Discovery](/learn/concepts/dns-discovery) | |
| 106 | +| [Run @waku/sdk in a NodeJS Application](/build/javascript/run-waku-nodejs) | Learn our suggested approach for using the `@waku/sdk` package within a NodeJS application | |
| 107 | +| [Debug Your Waku DApp and WebSocket](/build/javascript/debug-waku-dapp) | Learn how to troubleshoot your Waku DApp using debug logs and check [WebSocket](/learn/concepts/transports) connections in [nwaku](/run-node/) | |
| 108 | +| [Manage Your Filter Subscriptions](/build/javascript/manage-filter) | Learn how to manage [filter subscriptions](/learn/concepts/protocols#filter) and handle node disconnections in your application | |
| 109 | + |
| 110 | +:::tip |
| 111 | +Until [node incentivisation](/learn/research#prevention-of-denial-of-service-dos-and-node-incentivisation) is in place, you should [operate extra nodes](/run-node/) alongside the ones provided by the Waku Network. When running a node, we recommend using the [DNS Discovery and Static Peers](/build/javascript/configure-discovery#configure-dns-discovery-and-static-peers) configuration to connect to both the Waku Network and your node. |
| 112 | +::: |
| 113 | + |
| 114 | +## Get help and report issues |
| 115 | + |
| 116 | +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](https://discord.waku.org). |
| 117 | + |
| 118 | +If you discover bugs or want to suggest new features, do not hesitate to [open an issue](https://github.com/waku-org/js-waku/issues/new/) in the [js-waku repository](https://github.com/waku-org/js-waku). Your feedback and contributions are highly valued and will help improve the `@waku/sdk` package. |
0 commit comments