From 809c0e45b4477a49069b79a59fd8ae5598a9ae63 Mon Sep 17 00:00:00 2001 From: Mihai Date: Sat, 22 Mar 2025 18:35:26 -0400 Subject: [PATCH 1/3] fix asyncweb3 --- multicall/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multicall/utils.py b/multicall/utils.py index 7ea72b9..64c69cf 100644 --- a/multicall/utils.py +++ b/multicall/utils.py @@ -80,7 +80,7 @@ def get_async_w3(w3: Web3) -> Web3: # with incompatible synchronous middlewares by default. middlewares = [] if AsyncWeb3: - async_w3 = AsyncWeb3(provider=provider, middlewares=middlewares) + async_w3 = AsyncWeb3(provider=provider, middleware=middlewares) else: async_w3 = Web3(provider=provider, middlewares=middlewares) async_w3.eth = AsyncEth(async_w3) From c76344cc710e874482e6558174b3a4cae7a1d28a Mon Sep 17 00:00:00 2001 From: Mihai Date: Sat, 22 Mar 2025 18:44:33 -0400 Subject: [PATCH 2/3] make more robust --- multicall/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/multicall/utils.py b/multicall/utils.py index 64c69cf..ff1c2ed 100644 --- a/multicall/utils.py +++ b/multicall/utils.py @@ -80,7 +80,12 @@ def get_async_w3(w3: Web3) -> Web3: # with incompatible synchronous middlewares by default. middlewares = [] if AsyncWeb3: - async_w3 = AsyncWeb3(provider=provider, middleware=middlewares) + # 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) else: async_w3 = Web3(provider=provider, middlewares=middlewares) async_w3.eth = AsyncEth(async_w3) From 7f498dc41b47cbb7258ec32b6dd934443ce32656 Mon Sep 17 00:00:00 2001 From: Mihai Date: Thu, 27 Mar 2025 15:00:32 -0400 Subject: [PATCH 3/3] update and clarify minimum web3py version --- multicall/utils.py | 16 ++++++++-------- pyproject.toml | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/multicall/utils.py b/multicall/utils.py index ff1c2ed..853e766 100644 --- a/multicall/utils.py +++ b/multicall/utils.py @@ -56,6 +56,11 @@ def get_endpoint(w3: Web3) -> str: def get_async_w3(w3: Web3) -> Web3: + """Return an async version of the given Web3 instance. + + Compatible only with web3py >= v7.0.0-beta.2 (2024-03-11), + which renamed middlewares to middleware. + """ if w3 in async_w3s: return async_w3s[w3] if w3.eth.is_async and isinstance(w3.provider, AsyncBaseProvider): @@ -78,16 +83,11 @@ def get_async_w3(w3: Web3) -> Web3: # In older web3 versions, AsyncHTTPProvider objects come # with incompatible synchronous middlewares by default. - middlewares = [] + middleware = [] if AsyncWeb3: - # 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) + async_w3 = AsyncWeb3(provider=provider, middleware=middleware) else: - async_w3 = Web3(provider=provider, middlewares=middlewares) + async_w3 = Web3(provider=provider, middleware=middleware) async_w3.eth = AsyncEth(async_w3) async_w3s[w3] = async_w3 diff --git a/pyproject.toml b/pyproject.toml index b12da3f..3e7858e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,8 +7,7 @@ authors = ["banteg"] [tool.poetry.dependencies] python = ">=3.8,<4" cchecksum = ">=0.0.3,<1" -# These web3.py versions have a busted async provider and cannot be used in any multithreaded applications -web3 = ">=5.27,!=5.29.*,!=5.30.*,!=5.31.0,!=5.31.1,!=5.31.2" +web3 = ">=7.0.0-beta.2" eth_retry = ">=0.1.8" [tool.poetry.group.dev.dependencies]