Skip to content

fix asyncweb3 #112

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions multicall/utils.py
Original file line number Diff line number Diff line change
@@ -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,11 +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:
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
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]