Build A Decentralized Chat Using JavaScript & Rust (WebAssembly)

Create and deploy your own decentralized chat in just a hundred lines of code using Wavelet.

Kenta Iwasaki
Jul 4 · 12 min read

Well, let’s create a decentralized chat :).

What We’re Going To Be Building

This is what we’re going to be building.

The Backend

Bob made a chat service using MySQL and NodeJS. Bob’s chat got DDoSed by hackers. Bob is sad.
❯ rustup target add wasm32-unknown-unknown
❯ cargo new --lib chat; cd chat
❯ cargo build --release --target wasm32-unknown-unknown

Deploying The Backend

Generate a new private key, save your private key, load a previously-saved private key; then proceed to login.
Congrats! You just registered your first Wavelet wallet/account.
$claim [your public key/wallet address here]
After clicking the ‘75%’ button after attaining 500,000 PERLs from Discord.
Make sure to jot down your smart contract ID.

The Frontend

Calling get_messages()

The only smart contract methods which you have to pay nodes PERLs for to execute are ones that modify the blockchain.

Calling send_message(msg: String)

{type: "string", value: "Your chat message here!"}

Listening for changes to the blockchain

Conclusion

Enter your chat smasrt contracts ID into you made into UI we made for you to chat with your friends at https://perlin-network.github.io/decentralized-chat :).

Congratulations, you just made your very first, scalable, secure Wavelet Dapp!

Footnotes

Perlin

Powering the future of trade on top of the world’s fastest public ledger.

Kenta Iwasaki

Written by

Theorist at heart; engineer at scale.

Perlin

Perlin

Powering the future of trade on top of the world’s fastest public ledger.