Skip to content

Conversation

@wakamex
Copy link

@wakamex wakamex commented Mar 22, 2025

use middleware or middlewares argument as appropriate for the Web3py version

fixes: #110

@DefiDebauchery
Copy link
Contributor

DefiDebauchery commented Mar 22, 2025

This depends on what version of web3py that @BobTheBuidler wants to target. The middlewares kwarg was changed in 7.0 and there are a number of people still using v6.

I would like to see some modernization of this library for Python itself, but web3py v7 has introduced a lot of changes throughout that people may not be prepared to upgrade.

@wakamex
Copy link
Author

wakamex commented Mar 22, 2025

you're quick! what do you think about this?

# AsyncWeb3 switched to middleware instead of middlewares
# check if AsyncWeb3 has a middleware parameter
if hasattr(AsyncWeb3, "middleware"):
    async_w3 = AsyncWeb3(provider=provider, middleware=middlewares)
else:
    async_w3 = AsyncWeb3(provider=provider, middlewares=middlewares)

@BobTheBuidler
Copy link
Collaborator

Just specify in the docstring which web3py version(s) the change is for and then I'll merge. Thanks for this!

@wakamex
Copy link
Author

wakamex commented Mar 27, 2025

source for the change being v7.0.0-beta.2 (2024-03-11): https://web3py.readthedocs.io/en/stable/release_notes.html

@wakamex
Copy link
Author

wakamex commented Mar 27, 2025

if you're willing to bump the minimum web3py dependency to v7.0.0-beta.2 (or higher) then you can remove some of the AsyncWeb3 workarounds I think, like this one that does the if AsyncWeb3 check #102

@BobTheBuidler
Copy link
Collaborator

BobTheBuidler commented Apr 3, 2025

I prefer to keep the deps as loose as possible here and leave that choice to the user. The above workaround is fine, this code does not run in tight loops as it is so efficiency isn't a huge deal.

@Richymaestro
Copy link
Contributor

Is it possible to still merge this PR, with maybe only the first two commits? Still the multicall is not working when using web3py >7

@Richymaestro
Copy link
Contributor

Richymaestro commented Aug 6, 2025

In fact maybe its better to try/except?
if AsyncWeb3:
try:
# Try using 'middleware' (newer versions)
async_w3 = AsyncWeb3(provider=provider, middleware=[])
except TypeError:
# Fallback to 'middlewares' (older versions)
async_w3 = AsyncWeb3(provider=provider, middlewares=[])
else:
try:
# Try using 'middleware' (newer versions)
async_w3 = Web3(provider=provider, middleware=[])
except TypeError:
async_w3 = Web3(provider=provider, middlewares=[])
async_w3.eth = AsyncEth(async_w3)`

@BobTheBuidler
Copy link
Collaborator

BobTheBuidler commented Aug 6, 2025 via email

@Richymaestro
Copy link
Contributor

@BobTheBuidler #163 added it here, let me know what you think

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncWeb3 problem

4 participants