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] Typings and/or contract method autogeneration using web3py #3287

Open
gabrielfior opened this issue Mar 14, 2024 · 3 comments
Open

Comments

@gabrielfior
Copy link

  • Version: 6.15.1
  • Python: 3.5
  • OS: linux
  • pip freeze output
pycryptodome==3.20.0
pydantic==2.6.3
pydantic-settings==2.2.1
pydantic_core==2.16.3
pytest==8.0.2
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
streamlit==1.32.0
types-pytz==2024.1.0.20240203
types-requests==2.31.0.20240218
typing-inspect==0.9.0
typing_extensions==4.10.0
urllib3==2.2.1
web3==6.15.1
websockets==12.0
Werkzeug==3.0.1

What was wrong?

I'm using web3py to interact with a deployed contract. Instead of calling the functions by-hand and using error-prone strings, I would like to use auto-generated contract methods (similar to what Typechain (https://github.com/dethcrypto/TypeChain) does in Typescript.

Is there support for typings and/or autogeneration in web3py? If not, is there a package that achieves this?

Thank you!

@naoki-maeda
Copy link

Hello @gabrielfior

I also felt the need for an auto-generation tool, so I created one.
Please give it a try!
https://github.com/naoki-maeda/py-contract-codegen

@johnny-emp
Copy link

johnny-emp commented Sep 16, 2024

https://github.com/empyrealapp/eth-packages I built an implementation that I feel addresses this requirement. I think this could serve as an alternative to web3.py for typed bindings, or if there is interest it could be integrated into the web3.py toolchain.

https://eth-packages.empyrealsdk.com/getting-started/contracts/func/#struct-definitions might be a cool place to reference in the documentation

@slundqui
Copy link

slundqui commented Oct 10, 2024

We also needed auto-generated contract methods, and have written a package on top of web3py for this. Feel free to check it out!
https://github.com/delvtech/pypechain

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

5 participants