Status: Enabling decentralized communications with WakuJS with Franck Royer
ETH Warsaw·Thu, Oct 7, 2021, 12:00 AM
Speaker
BOUNTY LINKS: Status: https://gitcoin.co/issue/status-im/0xHack/3/100025685 https://gitcoin.co/issue/status-im/0xHack/2/100025680 https://gitcoin.co/issue/status-im/0xHack/2/100025680 https://gitcoin.co/issue/status-im/0xHack/1/100025679
Transcript
and we're back after the weekend welcome to xerox uh we are launching the first week of xerox hack uh with a workshop from status which will be conducted by frank roya uh team leader at waku he's going to do a 20 minute presentation and then 40 minutes of live coding if you have any questions to frank feel free to ask them in the hermit chat or on youtube and we'll make sure that they're answered um also make sure to to hang out on our discord frank is uh is there to help you with your uh projects um to make sure that your bounties that you will win the bounties from status uh we want to make your projects as good as possible uh so yeah i'm giving my voice to frank whoa welcome frank hi thank you and uh thank you very much so hi everyone um yeah so today we're going to talk about waku and gs waku so um as mentioned i am leading the gswaku effort i'm part of statues but i wanted to mention that statues has this new division that we call vac which is aimed to provide tools and libraries and infrastructure to the icm ecosystem so it's more about having some agnostic mbs tools statues use some of them but vac is really for the benefit of eastern ecosystem and at the moment the thing that we worked on the most is waku so let's uh get right into it all right there you go so trying to explain to you uh what waku is so i could do a lot of slides so instead just go for a short sentence so what could be to provide in an infrastructure and standard for decentralized off-chain private communications to the islamic ecosystem while considering the limitations of restricted resource devices so quite a lot to unpack here so let's just go slowly through our different keywords we have in there so the aim of waku is to provide you in infrastructure so what i mean by that is that you don't need to run your own nodes you don't need to deploy some adobe server to use waku uh waku comes with its own infrastructure like ethereum in the way that people are incentivized to run nodes so that as a deaf developer that wants to use raku you don't have to run your own infrastructure instead you can relay on waku to provide that for you standard so standard is more um so similarly to web3 so it's more about having a common way of doing things so whether you are building um an app or wallet you want to have one uh common way to to do communications and that's what waku is aiming to provide to you so standard has a bright party such common way of doing thing a bit like the web stream interface where you have one common way to interact with the blockchain um so yeah so it is decentralized of course so that's the only characteristic of of this solution decentralized so that same thing ethereum to avoid censorship having uh avoid single personal failures maybe legal risk and extra so um most likely if you look at uh you know it's not us running one server somewhere and everyone use it for communication it is decentralized system where anyone can hold a waco node and anyone can use the network for communication of chain so i just want to mention off chain in the way that the solution is not about sending messages on the blockchain and paying 20 whatever the gas fee are for each message no it's uh having a separate network that um will have some incentivization but you don't have to pay gas fees for each message um there are some protocols especially around spam where there is interaction or let's say there is ways to interact with the blockchain to lock some money so that you can kind of verify yourself and as a non-spammer situation but it's mainly an option system which is a second network by itself private so um it's private it's more about enabling uh builders so enabling developers if um if your dap needs needs and to an encryption or needs to keep some metadata private then waku enables it so the the way we build raku and we uh specify waku keep in mind that keep that in mind so that we can uh fit and um field purpose any purpose that an app may have so um yeah so that's part of private um and you can also decide not to do antoine inhibition you can also decide how much privacy you need depending on your use case communication so uh the aim of aku is sending and receiving messages in in various contexts um and that's basically the idea so messages can contain text images so it's a you know the payload is up to you but that's the main uh the main goal of waku communication sending and receiving messages and eastern ecosystem so it's it's built mainly for instagram i mean people could use it for something else but we are building within the eastern ecosystem and by ecosystem i mean any kind of anything that is bit on top of ethereum so we're trying to provide a solution that is generic enough that it can fit uh you know whether you want to send messages between adapt user to another dap user or you want to send a message from you as an operator or that builder to your users or you want to be able to use it to communicate with you um it's really up to you to decide what you want we want to uh to provide something that is generic enough so that the working system can use it i said that but it can be used a wallet uh only layer two you know coordination anything that you can think of finally restricted resource devices so just a complicated way to save funds um so waku v2 has been uh you know specified and beat with the funds in mind in the way that we wanted to be able to work um on on the phone where there is maybe limited data or limited availability meaning the phone is not always online and of course limited disk space and cpu so we we need this to work on on such uh in such environment so that your dab can work on the phone as well as it works on the desktop browser so um a bit more on the on the origins uh i think it helps quite uh it helps understanding where could come from so i say work with the time what actually mean is what could be too so um if you look at web3 so maybe for the all these among you know that web 3 come from yes it's web 2 the next generation web 3 but it's also the trifecta of whisper swarm and ethereum so whisper was meant for communication swarm for data storage and ethereum for the contract so the status app which is a decentralized messenger app first wallet and the browser originally one bit one bit was using whisper but what they quickly realized is that whisper is not really great for mobile phone environment main reason was for spamming protection for example he used proof of work so it was hard to find a way to have a proper fork difficulty which is okay for a phone to actually send messages but also for desktop not to spam the network and there was also new routing which means that a lot of messages uh where sana received from uh by the phones you know because there's no writing so you receive all messages means there was some bandwidth issues so from there statues created at first a whisper waku mod which then became with one which solved a number of these issues and reflecting back to uh to the lesson learned um we designed and created waco v2 which is a bit more i would say an improved approach of uh a waku uh of work v1 and this um so by few ways so for example it's uh it is bit on lip b2p uh or could be too easy for p2p and and that's what we are currently uh we're going to talk about uh today um as the moment the status app use work v1 and a4 ongoing effort to make it use waku v2 okay um i think so from a personal experience and an opinion we can see if you look at ethereum and what has been built on islam so far you could see that when it was created maybe it was a bit too early for whisper and swarm um for example today you know most nfts are backed up on ipfs which kind of becomes the de facto replacement of swarm artists you know from some point of view um and there was no you know maybe not as much need before um i feel like it's the same for whisper and communication now that we have uh layer two and grants tokens we can see more need for a decentralized communication solution which was maybe not the case when when instagram was created so uh definitely a good time for waco v2 to uh to be live and be used all right so um what implementation so i just want to give you a bit of a view on the ecosystem so what we have we have nimaku so written in nim which is a high availability full node which is the note that will be incentivized uh in future for user to run this node on and it can also be used as a backend library um status is running a few of these nodes so that um you know even if it's not incentivized yet you do have a network and you can already start to beat things and start to uh to test them out we also have a gowaku that is used to integrate in the status app on the mobile um because this app is many bytes in go with other tech and then we have gsuaku which is um what i work on the most and that's what is uh you can use so it's a client focus library and the aim is its aim is to allow you to integrate waku in your dap or wallet or anything you want to build so in terms of features so in terms of so what does goku give you so as a month so there's quite a few protocols um so all those so all the code source is uh source code is open source and very permissive license like mit apache across across the board and the rfc's specifications are also open source and everyone is welcome to to read them and propose new or proposed modification on the specification if um if there is any improvement they want to see um at the moment i want to talk about many street protocols that are those ones that will get you going so we have relay um which is for those who know le p2p relay is based on pub sub and gossip sub so that's for the near instant messaging so vulnerable send message and receive message is live because uh because of the you know the recipe resource devices so funds uh we need to be sure that we cater for scenarios where an iphone is offline for example so that's why we have the store protocol so store protocol is mainly used once you are resuming connectivity so once you have a network again you can contact the full node and the full node store all messages they see on the on the relay network so you can contact them and they will send you the messages that you missed so you can contact them um with time with the time frame for example which is a working process we have or just contact them and they give you all the messages that uh that they have seen so that you can then you know show to your user any messages they may have missed from the roller network and then finally there is light push so there's no green box there because it's working progress on jswaku that's more for i would say scenarios where you don't have a very reliable connectivity then you can push message directly to a full node so that the footnote can then relate to the network of course there's some drawback on privacy there to take in account um we have other protocols which are specified for example at the moment we're working on a spam protection protocol which interacts with the contacts in the blockchain and that's currently working progress as the implementation there is links to the rfc so you can have a look yourself to see what what we offer all right so now from from a developer perspective whether you're adapt developer wallet developer while using waku so if you need um some kind of communication in your dap whether it's user to user our operator to use their kind of notification or maybe use the exercise for either for maybe voting things like that you today you can go the simple route which is spin up an aws server and have some central and add a central item in your architecture or instead you can use waku the first thing that works does is that it removes the need of infrastructure for you so you don't have to spin a server instead you use work network and you can rely on people running working nodes um it's also an out of the box solution which is what we try you know what i discuss uh in the first second slide about standards or something we should just walk out of the box just import npm library and um and get started and the thing is that so the back team we have researchers and developers working on raku so that if you were to uh to if you want yourself to serve communication and do in decentralized manner this comes from uh this comes with a plethora of problems so what we're trying to do with waku is we're trying to solve this problem for you so that you are able to have communication in your dab without having to think too much about how is this solved um i would say it's exactly when you beat the dap on ethereum you don't have to think uh on how to fix ethereum's scalability but of course you are more than welcome to understand the problem and participate participate to the solution but you can also purely focus on your dap unique setting point and not have to think too much about the research problems that they have behind communication or scalability for crm so that's kind of the idea of what we just give you these tools and solutions so that you can focus on your dap unique setting point all right so um so after presentation i do some live coding but here is a small uh code example that you can have a look at so written javascript so the so jswaku is written in typescript which means that um you can use it in javascript of course but if you use typescript or clojurescript you have the types as well which makes things a bit easier so library is called jswaku and um first line you just start your waku node with what could create then you can connect to appear so here you can just decide to uh you know connect to one of your peers or we also have some helper functions to automatic to connect to the status peers so you don't have to have something hardcoded you can use a helper to grab the status nodes at the moment we haven't looked too much into discovery we are just waiting to solve other problems first and once we have a more you know a wider network and we can look more into uh ways to do discovery in a less centralized manner um so if you want to look at uh messages sent on the network so what you can see in the so what could relay so using the relay protocol um and you have ad observer this gets you some messages and you can just you know log the messages um and then you can notice i in someone argument i have this michael app string so to ensure that your dap only processed messages they are entitled into we categorize all messages with content topic so each message has a content topic and then it really depends on your application so um you may look into using a content topic that already exists if you want to have some interoperability with other dapps or wallets or you may create your own content topic if you are doing a unique use case and you just want your dab to uh to have these messages to process and see these messages um now to then send a message um so you can see on the next line message equal work message formula string ptf8 string so again to create a message um so you can pass a string and then your content topic um here i created from utep's utf8 string as a simple example but of course you can pass a byte array it's like having bytes as a payload so that on your side you can create your own data structure which match the purposes of your application and pass that into working message so it is you know generic enough you can pass any kind of uh of that array um and then handle yourself how you want to decode and encode your your data structure and then finally to send a message and do away to a cool listen and then you send a message to the to the network to any peers that is connected to so that's a pretty much a very simple code example there um so yeah so now let's talk about the bounty so bounty three for uh statues is build an app with gswaku so in terms of ideas whether it's private direct messaging chat rooms notification there to coordination so i think there's a lot of use cases there uh my creativity is quite limited so i'm just looking forward to see what you are going to be there with waku um in terms of submission requirements it just needs to be a fair usage of the of the adapt so um you know if you just use roku to do some communication but then main most of your communications are done just from centralized servers and contrary uh you know contact in um the but if most on you know all your peer-to-peer holders to use their communication are done by waku then uh the happy uh the project will be eligible um of course communication doesn't need to be a a central point of view of your dab so i think that's what's quite interesting is that you could build a dab for for specific purpose and have communication as a good way to you know have an extra feature that enhance the dab and then use waku for that um i'm really looking forward to uh to see what you build um all right so idea so here's a couple of ideas i have um but again i'm really looking forward to uh to your ideas and your creativity um i feel like institute there is a number of ideas we have been looking into and thinking uh thinking of but i'm looking forward to some fresh ideas um so one one idea which is uh to have direct messaging between dap users and that could fit maybe your dap is uh you know nfd focus for example and you could uh have a nice um site feature for communication where you can like each other nfts or maybe have some private auctions or sending you some private messages to say hey i want to buy your nfc for that much um there's some some uh some possibilities or have something like a uh like a chat room where maybe people will discuss uh troll box within your dab for example and another uh more advanced idea is uh to use waku as a way to anonymize um some of the ethereum transactions so that's the transaction per se but the broadcasting of them so if you look at most you know wallets nowadays we don't so users typically don't run their own node but instead rely on specific service providers so which means that when you use your wallet and you connect to this size wider they can they can dox you you know so you send transactions to them so that you know when you get balance for some transactions they can log your ip and say okay this guy most likely owns this address because it's a transaction uh that spam from his address so as a first step to try to uh to help trying to fix that uh you could use the welcome network to broadcast transaction um on one side the wallet broadcast connection uh to the local network and on the other side you use uh nimwaku for example and the there is a json rpc interface on it to listen to local messages which are transaction and then you know sends and then this roku uh nimaku or this bridge node can submit transaction to a full node this of course doesn't solve you know all price issues it's just like one uh one step uh to to helping with that so something to uh to think about [Music] um yeah so that's it for quantitation yeah okay um so here are some links i will transformation uh slides in the discord after the actors workshop um but links bounty links to the repo there is one showcase which is a a shot app so you can play around with which is a built-in uh in react.js using uh waku and uh we have spec we have a forum we have the discords as well um once you know the racket finish feel free to join our discord status um all right so if you have any questions now is a good time because i'm going to change screens to share my uh to share my screens for um for coding purposes so just give me a couple of minutes yes uh right back on so if i can have a quick message someone confirming that you can see my screen it'd be great um i know the code is the smallest amount so i'm just going to increase that okay all right so for now just uh have a look on the right hand side so yeah okay cool all right awesome so just for now just a terminal so uh let's get started so i'm just going to um just create a so as i mentioned we have a chat app that is uh so reactive which that is available and actually goaku and nimoko waku also have um a little chat app to uh to interact and that's how we do some dog fooding just to use network uh you know as people are being deaf we just want to use network so we have this little chat feature so we're just going now what we're going to do is that we're going to use jsoku to create a react.js chat app from scratch okay so just on the right hand side of the screen so let's start with npx create react app and let's call it chat roku all right so let's jump in the repo i'm just going to do some cleanup here just so just install those packages okay just waiting a bit live coding hopefully everything will go well all right uh let me just check something because we have some issue uh with bubble or some tea so let me just check let's work good on the versions yeah so good and then anti-install jsoku i can start to open this new project in my id so here we go okay okay all right so let's just increase the font here yeah all right so i'm just going to uh do um npm run start and that gives me a nice browser window to show my react up i'm just going to move that away okay here we are so um yeah so i have my react app here ready and yeah i start coding so fgs okay just checking uh is font ok and you just quickly check in the chat confirm the font is okay i got here the chat okay all right just yeah just jump in the live chat if uh if there's any issues i'll i'll keep a keep look there okay cool all right so all right first thing we want to do is create a waku node so it's a it's an async process to create working notes we are going to use as a use effect function in react so um i'm going to have my roku node as a property of my app so just using use state from react now so if i don't have my waku node so if not waku then let's create a waco node so just going to call it waku node for now and uh what we said we said waku so automatically imported from jsoku dot create all right for now i don't want to space any options um yeah let's use a way to sync for now i mean you can use um or let's actually just do combination let's do a then just make it easier in react i think fine all right so what could create and then we end up with a working node um let's just let me block something let's have a waku node created and maybe we can have the pid so for those who are not familiar with the p2p as a pid is this unique identifier for your node okay here all right and um so we're going to log that we have the node created and then we're going to save it in the state of or up i go all right compiling expand the console here alright comex console bigger there you go cool all right so let's go in already i can see here waku node created all right so we have waku node awesome um next thing we want to do is connect to other nodes so as i mentioned we do have a little helper the amount which is called gas status fit nodes um because at the moment we're basically the only one running nodes uh this is quite helpful but once we have a more heterogeneous network more people running these nodes then we can move into having some discovery so um guest status fitness uh does a query to uh to status server to know what nodes are going on are available are running so we have a string of addresses basically um and from there we're just going to to connect to them okay so node dot for each so they're just analysis we can directly pass them to our work node so we're going to work node dot dial and pass the address so actually i should i'm going to set the waku just at the end here yeah so just keep the change property at the end so as soon as we start the work node we're grabbing status nodes and then this return an array of strings that are different multi-addresses and we're just going to for each of them we're going to dial all of them so then we can just um just lock something console.log it's going to connect it to all right um yeah let's have a look i inject check this chat to see everyone is fine oh yes i reset just here all right okay okay okay my connection seems to be a bit poor let me just all right yeah looks like um oh no the screen share i think it's gone just no my foreign hi everyone i'm back okay can you hear me can you see my screen uh all right can you hear me now let me know yes yes okay can you see my screen [Music] okay so we are back on [Music] okay so yes we have our changes here um i was just looking for now we're just working with the console um here so just picture on raku um yeah so we have not created and then we wanted to connect to each node so yeah just uh yeah let's just refresh on that alright so okay then back to diet hmm so we grabbed the rashes and then we died our address i just have a little console log to see if i'm missing something obvious here that should be fine but obviously it is not okay let me just quickly cut my uh cheat sheet um huh okay just uh checking that so let's maybe add some more holes i wonder if the nodes are done now we have a node here available i i just thought that live coding would be uh challenging but uh so i'm just checking yeah should be fine should be fine okay so what i'm going to do yeah just cut here so catch hello so here and then oh okay so if i know all right we had a uh it's okay so that's where we are so we are connected we are dialing nodes and now we are connected uh i wonder if if someone just can deploy the node during the demo i don't know i have to have a look after okay so what next we want to send yeah let's receive um some messages so to do that we're just going to jump um so before we connect we are going to do is actually what we had in the slide which is um which is just add an observer all right to just look for new messages so i'm going to store these new messages in as a state of my app so just again set some messages setting messages using you state um or for now she's going to have a message at time all right so setting message um so it's just adding here forward to that so just the way that use effect work uh just much just need to use effect um what dependency needs to watch so these are change and uh you can you can run the function so um yeah so let's add observer so we have our keynote and we're going to look at uh new messages on the relay network we're going to add an observer so the observer needs to argument so we're going to have a callback which process waku messages so i'm just going to grab my waku message and here i'm going to process it so um in this case for now i'm just going to set new message i'm going to directly you know add work message to um to my state i'm just going to log it says perceived okay um that's fine now yeah so now let's do something with this message okay so a message just is is so second argument sorry second argument is a content topic so as i mentioned each message has a content topic so we categorize with that so um for this dog fooding app so this app that we use to uh the chat apps that we use to play uh with things and i'm sure that you know that work is working i'm trying the new picture or uh content topic is ding poo because uh or that lead is in uh is in taiwan uh so yeah so i'm only interested in in these messages so i'm going to just pass one contact to big here so that i only process messages which have this content topic now let's jump just do some uh create code again so just come disclaimer i am not a hack developer so uh i'm doing my best here all right so new message uh and so this message is block message so at this stage i'm just going to grab the payload as utf-8 so just like a little helper function here uh it helper get so yeah so if it's only 5 um that just say oh you have good messages consider as utf-8 but again we will come back to that most likely you won't have the task with your hair all right so let's have a look now cool um it's not it seems not like some of the nodes here it's connected to connected to so i did repeat i did try this few times there's one node it doesn't like okay so it looks like there is one node that is done so for now it looks like there is one node that has some difficulties today [Music] um so oh yes at the end wait what do you do ah that's in the wrong place ago okay yeah so the screen will go as well it needs to go here all right so cool so that's a message so as i mentioned we do have shut up running somewhere so it's on the github page so i'm just going to open the chat app that i have running on the page just going to wait for it to go to beat and set that into the turn yeah it's fine all right hello world yay hello world so we're good so um one thing that you may notice here that we have a trench character um and and here that's the nickname here so you can see my nick so i'm just going to sfgs pages all right so uh that's my nick and here's a strange character so i kind of cheated here because actually as the pillar of the vocal message is not a ukfa string but it's a it's a protobuf pedo but because there's no extra you know it works because uh it it keeps the string as you tf8 so as i mentioned you can use byte arrays and you can you know put whatever pillows you want so instead of chat app we have a a chat message payload and because something we use quite often for concept it is added to library but i expect you to come with your own payload depending on your own use case and yes look if there is any questions so far okay five minutes all right i'm going to jump uh okay what is that message try to jump to the payload okay so let me say so what i'm going to do here is that instead of having a welcome message i'm going to have a short message and um just decoding so message dot period so the payload as a battery okay here i know we have short message and um answer this new message now is a chat message so i can just going to have a very simple string where i'm going to say short message message oh it's new new message so this time the pillow as utf-8 is actually of course usage here uh shut message is not defined yeah um yes there you go yeah all right okay so hello again i want to pass it again there you go so this time it's decoding things and yeah so let's have quickly uh how to send message it's going to be it's going to be short in time it's going to wrap up yeah um i can so i think yeah so that's the basic uh a basic idea so i have a another demo so i have a repository where i did the demo uh fully so you are more than welcome to have a look there all right so let's go to questions uh who's using this on class communication means that the dap would be hundred percent of the time yeah so exactly so asmr a question from osama whether by using decentralized communication means that the dap would be 100 up of the time uh opposed to having a centralized server so yes absolutely but again you need to look at your own dap architecture understand what are the elements so using waku you can offload communication to baku um but then you also have questions you know where do you store your uh your dap you know like for example where do you from where do you serve as a javascript code for your dap and this could be centralized as well or you have to have a look uh somewhere else so um that's one thing that you may want to uh to look into but with roku i definitely help you decentralize some part of your dab okay so if you have any other question please go for it um and i will share the slide in the in the zero exact discord so that you can have a look a bit more at the example um i am a free on this course available on on the status chart of this course so feel free to ask any question you may have hey um frank thank you very much for your workshop uh to everyone attending uh feel free to join discord you can get any answers uh questions answers to any questions you might have and up next is um alberto vera uh he will tell you more about bounties from moonbeam and give you some technical backgrounds that he needs to compete for the bounties albertos will be here in a minute let's let's give the stage to him
Automatic transcript — names and jargon may be misspelled.