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/...',
'wss://mainnet.infura.io/ws/v3/...',
]))
# or
w3 = Web3(FallbackProvider([ # RPC endpoints list
'http://127.0.0.1:8000/',
'https://mainnet.infura.io/v3/...',
'wss://mainnet.infura.io/ws/v3/...',
]))
last_block = w3.eth.get_block('latest')
This provider tracks currently used endpoint internally and switch to the next one on error or fails if no more endpoints to switch to.
This provider sends requests to the all endpoints in the sequence until response received or endpoints list exhausted.
poetry install
- to install depspre-commit install
- to install pre-commit hooks
poetry run pytest tests