I have some javascript code that I need to embed in my substrate runtime. It's not possible / practical to rewrite the javascript code in rust. I was wondering if instead it would be possible to convert the javascript code to wasm and embed the wasm in the runtime. Intuitively it seems like this should be possible however I'm not sure on the technical details of how the integration should work. Would appreciate if anyone could provide some guidance / direction.

1 Answer 1


I don't think that compiling JS to wasm is possible currently.

Effective compilation requires GC at least, and that Wasm extension proposal is still under development. It's also not clear if a proposal like that would be incorporated into Substrate since it ultimately depends on how it will work.

Then there are inherent problems with compiling a dynamic language such as JS ahead-of-time. This is especially so when targeting Wasm.

  • It looks like JS can be compiled to wasm for a wasm32-wasi target using github.com/Shopify/javy.git. However I'm guessing it wouldn't be compatible with substrate's wasm32-unknown-unknown.
    – TauLepton
    Oct 18, 2022 at 19:48
  • 1
    If you look closer, javy bundles the given JS source code with QuickJS, an interpreter. No compilation is happening. Actually, my original answer mentioned a similar approach, but I decided not to post it. The problem with such approaches is that they are complex and very inefficient. Something that you want to avoid when building a blockchain.
    – pepyakin
    Oct 19, 2022 at 15:00
  • This makes sense, thanks for taking the time to clarify!
    – TauLepton
    Oct 19, 2022 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.