Why WebAssembly will Turbocharge P2P App Development and the Holochain Tech Stack

Holochain Dev Pulse 03

Summary

We are really excited about WebAssembly! Since Holochain is a framework for distributed computing and distributed apps, by moving to Rust and WebAssembly we are creating a foundation on which a massively broader number of people will be able to build P2P applications. We believe this means Holochain will play a critical role in building the P2P app ecosystem of the next Internet.

Highlights

1. “WebAssembly is JavaScript’s Nitrous Boost!”

2. Multi-agent Scenario Testing Pivotal Part of Developer Experience

3. Serialization Changes Coming Soon!

4. Holochat App in Rust

5. We’re Looking for Rust Devs!

Details

What’s coming up? The Holochain Developer Rust Preview Release for DevCamp #2 will be released by November 29th.

1. “WebAssembly is JavaScript’s Nitrous Boost!”

A lot of people are asking us why we seem to have dropped first-class support for JavaScript and adopted WebAssembly (WASM) instead. JavaScript is an easy language to code in, every developer knows it, and WebAssembly is just plain unreadable. Why would we say goodbye to one of our major selling points?

From that perspective, we have potentially increased prospective Holochain developers by 10×.

We’re actually saying hello to possibilities that extend far beyond what our small team can deliver alone. By choosing to go with WebAssembly, we automatically get open-ended flexibility that can only get better as WASM grows in popularity and gains support for new languages. If you consider the total number of developers who are familiar with Rust, C, C++, Java, Go, PHP, Python, or TypeScript, you can imagine how this choice would impact the advancement of Holochain development. From that perspective, we have potentially increased prospective Holochain developers by 10×.

It’s huge that we are using WebAssembly to support the era of P2P application development for many reasons. The majority of the DLT/blockchain technologies require developers to use specific languages that are not flexible and don’t accommodate the developer. By building on Holochain instead, you can build apps in the language you know and are comfortable using. Ethereum is exploring eWasm, but it’s still in development. WebAssembly is getting a reputation for being pursued by DLT/blockchain projects for various P2P use cases.

It’s huge that we are using WebAssembly to support the era of P2P application development for many reasons.

WebAssembly isn’t just for the web either. It’s crazy how many people banded together to create it — this is a cross-browser, cross-platform, cross-language initiative. It’s become an elegant solution for computing in our diverse world.

But we did also have browsers in mind when we chose WebAssembly. The Holo ‘light client’ library needs to run zome functions in a user’s browser, which means that they need to be able to download and run an app’s DNA, regardless of what language it’s written in.

It’s also fast, because it lives ‘close to the metal.’ Our Holochain prototype used a JavaScript interpreter which made zome functions slow to start and execute. A WASM hApp should run much faster.

We could go on, but we’ll let others speak about it:

“Being heralded as a game changer for the Web and performant, cross-browser execution, WebAssembly is a standard being developed by the W3C group for an efficient, lightweight instruction set. This means we can compile different types of programming languages ranging from C/C++, Go, Rust, and more into a single standard that can be run almost natively in browsers as an alternative to JavaScript. WebAssembly, or WASM, for short, is memory-safe, platform independent, and maps well to all types of CPU architectures efficiently.”

The idea that you could write smart contracts in JavaScript blew people away, but in reality, you could only write prototype-level P2P applications in Javascript, not production-level. It’s notorious for being memory inefficient, and its quirky scoping rules and type semantics makes it easy for an unsuspecting developer to introduce vulnerabilities. Now with Rust, you can build validation rules for Holochain that you can trust. Learning Rust might be an uncomfortable new journey for you to embark on. But don’t worry; you will become more comfortable with it.

Where does that leave JavaScript? We’re leaning on the WASM community to build a compiler, and we believe AssemblyScript is the furthest along. It’s a subset of TypeScript (which itself is a superset of JavaScript), so it feels very comfortable if you’re used to JS syntax. The AssemblyScript developers have been incredibly helpful and responsive to our requests, and in turn we’ve pushed new features upstream (e.g., JSON support). It’s showing us how much stronger everyone becomes when we build good relationships and leverage each other’s strengths.

We’ve put our AssemblyScript HDK on pause for now; we’re waiting for the low-level Holochain API to stabilize a little more, along with a few things that AssemblyScript doesn’t support quite yet.

If Rust and AssemblyScript aren’t your thing, there are many other languages that compile to WASM. And don’t forget that you can still code your front-end in whatever language or toolkit you like — browser-based UIs can take advantage of the full JavaScript ecosystem, and the Holochain core library can be used in anything that can target C bindings.

2. Multi-agent Scenario Testing Pivotal Part of Developer Experience

We have published a new release for Holochain-nodejs, which is an important step towards multi-agent scenario testing. We are using node.js as our main test environment. And in order to use Holochain-rust as a teaching tool for DevCamp, we need to have multi-agent scenario testing.

In order to have a multi-agent scenario testing environment, we need three things:

Support in the Holochain-nodejs library for multiple container instances (one for each agent);

Implementation of networking abstraction layer; and

A virtual networking layer that mimics a functioning Holochain network on one machine (almost done).

We’ve completed the first two, and are on track to complete the next one soon. This setup will ensure that the mock implementation matches the API of the real implementation. From a development standpoint, it will mean you can write the exact same code and easily flip between the mock or production network. This gives you the power to create a ‘testnet’ on your own machine before you deploy your app into the wild, but also lets you move onto a real network to test against the sort of edge cases you can only discover in real-life situations.

3. Serialization Changes Coming Soon!

There is a significant change coming that will impact developers. The structures that shuttle data between your app’s DNA and Holochain Core will change soon; HDK developers will need to update their serialization code, and the function arguments and return values that DNA developers interact with will be slightly different. We will be providing more information in a future Dev Pulse post. For technical details, see the JsonString serialization section on Dev Pulse 02.

4. Holochat App in Rust

The HoloChat DNA has been re-written in Rust. The app’s DNA will be connected to the existing browser-based HoloChat GUI. We are going to use this as a our demo app for DevCamp #2. This is a special app with a personal connection; it is our Holochain core dev Nico’s first app prototyped on Holochain. He created it at the 1st Holochain Hackathon back in 2017! It’s an awesome app and we are excited to see it being improved and ported to Rust.

5. We’re Looking for Rust Devs!

Are you interested helping us change the distributed computing and app development landscape? We are actively looking for skilled Rust developers. Check out the details about the Rust Developer Position or Apply here to join our global team!

Imagine millions of people building p2p apps

Contribute to Documentation

There is a deep commitment on the Holochain dev team to cultivate a culture of contributions and to make it relatively easy to participate. We would like to invite developers to contribute to the documentation.

Holochain Book Links

HDK: https://holochain.github.io/rust-api/0.0.1/hdk/

Zomes: https://holochain.github.io/rust-api/0.0.1/hdk/macro.define_zome.html

Rust: https://holochain.github.io/holochain-rust/

Developer Questions?

Find answers to frequently asked questions

Connect with the developer community. We want your feedback.

Think we can improve our content ? Let us know! We’re open to content requests and suggestions — post them on our Mattermost Chat, Holochain/Tech Q&A channel.