Provider that accepts multiple endpoints.
$ pip install web3-multi-provider
or
$ poetry add web3-multi-provider
from web3 import Web3
from web3_multi_provider import MultiProvider
from web3_multi_provider import FallbackProvider
w3 = Web3(MultiProvider([ # RPC endpoints list
'http://127.0.0.1:8000/',
'https://mainnet.infura.io/v3/...',
]))
# or
w3 = Web3(FallbackProvider([ # RPC endpoints list
'http://127.0.0.1:8000/',
'https://mainnet.infura.io/v3/...',
]))
last_block = w3.eth.get_block('latest')
This provider keeps track of the current endpoint and switches to the next one if an error occurs. It fails if no endpoints are available.
This provider sends requests to the all endpoints in the sequence until response received or endpoints list exhausted.
These providers are async versions of MultiProvider
and FallbackProvider
respectively. They may
be used with instances of AsyncWeb3
.
from web3 import AsyncWeb3
from web3_multi_provider import AsyncMultiProvider
from web3_multi_provider import AsyncFallbackProvider
w3 = AsyncWeb3(AsyncMultiProvider([ # RPC endpoints list
'http://127.0.0.1:8000/',
'https://mainnet.infura.io/v3/...',
]))
poetry install
- to install depspre-commit install
- to install pre-commit hooks
poetry run pytest tests