Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: wasm32 / emscripten support #3056

Open
3 tasks
joemarshall opened this issue Jul 21, 2023 · 4 comments
Open
3 tasks

Feature: wasm32 / emscripten support #3056

joemarshall opened this issue Jul 21, 2023 · 4 comments

Comments

@joemarshall
Copy link

So, I did some work on running web3.py on webassembly / emscripten, so as to be able to run it in a web browser / jupyterlite notebook, without having to install any software on the user's machine.

This is potentially useful for teaching purposes, to be able to run demo code in the browser, but also worth doing, as webassembly is gaining quite a lot of traction in container / cloud platforms.

In terms of how this works, I see this work as being possible in multiple stages, each of which gains some functionality:

  • Remove / make optional dependencies based on system.platform being wasm32-emscripten/ wasm32-wasi. Currently, aiohttp and websockets specifically don't work on webassembly. It is possible to run web3.py code by hacking in dummy modules for these two. This gets us the basic ability to run synchronous web3 calls, and to add emscripten to the project CI, so it keeps working.
  • Add emscripten provider in web3.py for async_rpc, and websockets client connections. This would allow most functionality of web3.py, except for local ipc support. Currently aiohttp and websockets libraries don't have support for emscripten; it is possible that they won't, because there is some functionality of the libraries that will never work (server side anything), and even if a polyfill is made, some functionality may not behave exactly the same. I think it is probably worth having specific emscripten providers for this here instead..
  • Potentially add support for ipc / geth on wasm32-wasi. This would be the final piece in the jigsaw in making all functionality work in webassembly container platforms, but to be honest I don't know if it is worth it - it will probably never work in browser / emscripten based webassembly.
@wolovim
Copy link
Member

wolovim commented Jul 25, 2023

i'd love to support learners with a hosted version of web3.py!

couple things on my mind as i read:

  1. would this be equally supported in mobile browsers? that would be compelling.
  2. maintenance impact of each stage?
  3. who's the audience? if just newcomers, a pretty limited version might be just fine.
  4. are there other advanced or interesting use cases that come to mind?

@ameya-deshmukh
Copy link

@wolovim would love to assist you in this! Can I take it up?

@wolovim
Copy link
Member

wolovim commented Aug 2, 2023

@ameya-deshmukh thanks for offering! just checked in with @joemarshall who's down the rabbit hole already. we talked about an MVP version that he's getting started with. keep an eye out for updates or opportunities here.

@joemarshall
Copy link
Author

@wolovim An initial PR that lets you build and run web3 on pyodide is here #3088

In the end I had to mock the aiohttp and websockets modules - the positives are that it gives you nice errors if you try and use async things - the negatives are that it is micropip / pyodide specific (but then pyodide is currently the only web python with decent package loading anyway). The alternative of separating out async would require quite a lot of code reorganisation in web3.py. Thoughts welcome on it. I guess I see it as being a stepping stone towards a time when pyodide supports aiohttp (client only) and websockets clients properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants