vac.dev/_posts/2021-05-21-js-waku.md
2021-05-24 12:56:28 +10:00

5.9 KiB

2021-05-21-js-waku.md--- layout: post name: "Presenting JS-Waku" title: "Presenting JS-Waku" date: 2021-05-21 12:00:00 +0800 author: franck published: true permalink: /2021-05-21-js-waku categories: platform summary: "Presenting JS-Waku" discuss:

After almost three months working on JS-Waku, we thought it would be a good time to give it a proper introduction.

First, let's review what is Waku v2.

Waku v2 comes from a need to have a more scalable, better optimised solution for the Status app to achieve decentralised communications on resource restricted devices (ie, phones). We see the need of such solution in the broader Ethereum ecosystem, beyond Status. This is why are building Waku v2 as a decentralised communication platform for all to use and build on. If you want to read more about Waku v2 and what it aims to achieve, checkout What's the Plan for Waku v2?.

Since last year, we have been busy defining and implementing Waku v2 protocols in nim-waku, from which you can build wakunode2. Wakunode2 is an adaptive and modular Waku v2 node, it allows users to run their own node and use the Waku v2 protocols they need. The nim-waku project doubles as a library, that can be used to add Waku v2 support to native applications.

We believe that dApps and wallets can benefit from the Waku network in several ways. For some dApps, it may make sense to enable peer-to-peer communications. For others, machine-to-machine communications could be a great asset. For example, in the case of a DAO with a governance token, Waku could be used for gas-less polling. Enabling the DAO to notify their users of a new poll, and users to vote without interacting with the blockchain.

For this to happen, we need to give developers a library which is easy integrate in their dApps: JS-Waku.

JS-Waku is a JavaScript library that allows your dApp, wallet or other web app to interact with the Waku v2 network. It is available right now on npm: npm install js-waku.

As it is written in TypeScript, types are included in the npm package to allow easy integration with TypeScript, ClojureScript and other typed languages that compile to JavaScript.

Key Waku v2 protocols are already available: message, store, relay and light push, enabling your dApp to:

  • Send and receive near-instant messages on the Waku network (relay),
  • Query nodes for messages that may have been missed, e.g. due to poor cellular network (store),
  • Send messages with confirmations (light push).

We focused the past month on developing a ReactJS Chat App. The aim was to create enough building blocks in JS-Waku to enable this showcase web app. Most of the focus was on getting familiar with both the Waku v2 RFCs and the js-libp2p library that we heavily rely on. Soon, we will use it daily for dogfooding purposes.

JS-Waku is the second implementation of Waku v2 protocol, so a lot of effort on interoperability was needed. For example, to ensure compatibility with the nim-waku reference implementation, we run our tests against wakunode2 as part of the CI.

As we built the web chat app, we were able to fine tune the API to provide a simple and succinct interface. You can start a node, connect to other nodes and send a message in less than ten lines of code:

import { Waku } from 'js-waku';

const waku = await Waku.create({});

const nodes = await getStatusFleetNodes();
await Promise.all(nodes.map((addr) => waku.dial(addr)));

const msg = WakuMessage.fromUtf8String("Here is a message!", "my-cool-app")
await waku.relay.send(msg);

As more developers use JS-Waku, we will evolve the API to allow for more custom and fine-tune usage of the network while preserving this out of the box experience.

Next, we are directing our attention towards Developer Experience. We already have documentation available but we want to provide more: Tutorials, various examples and showing how JS-Waku can be used with Web3.

If you are as excited as us by JS-Waku, why not building a dApp with it? You can find documentation on the npmjs page.

Even better, you can simply join us in building JS-Waku as we are currently have a position open: js-waku: Wallet & Dapp Integration Developer.

Whether you are a developer, you can come chat with us on Discord #waku (core development) or #waku-support (dev support) (soon to be migrated to Waku!). If you have any ideas on how Waku could enable a specific dapp or use case, do share, we are always keen to hear it.