Web3.py compatible async providers that supports multiply RPC URLs
This library allows to create a w3
instance with multiply RPC URLs to prevent failures when a node is down by choosing another one by cycle.
- HTTP async provider
- WebSockets async provider
HTTP w3 provider
import web3
from web3_async_multi_provider import AsyncWSMultiProvider
provider = AsyncHTTPMultiProvider(
providers=[
web3.AsyncHTTPProvider("https://eth.llamarpc.com"),
web3.AsyncHTTPProvider("https://rpc.flashbots.net"),
]
)
WebSockets provider
import web3
from web3_async_multi_provider import AsyncWSMultiProvider
provider = AsyncWSMultiProvider(
providers=[
web3.providers.WebsocketProvider("wss://example.com/"),
web3.providers.WebsocketProvider("wss://google.com/"),
]
)
And then add it into Web3
:
w3 = web3.Web3(
provider
modules={"eth": [web3.eth.AsyncEth]},
middlewares=[]
)
print(await web3.eth.chain_id)
Via PyPI:
python -m pip install web3_async_multi_provider
Or via GitHub
python -m pip install https://github.com/deknowny/web3-async-multi-provider/archive/main.zip
Check out site Contributing section