ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.89k stars 1.67k forks source link

Feature: wasm32 / emscripten support #3056

Open joemarshall opened 11 months ago

joemarshall commented 11 months ago

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:

wolovim commented 11 months ago

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 commented 11 months ago

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

wolovim commented 11 months ago

@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 commented 10 months ago

@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.