create_multi_provider_web3
Documentation for eth_defi.provider.multi_provider.create_multi_provider_web3 function.
- create_multi_provider_web3(configuration_line, fallback_sleep=5.0, fallback_backoff=1.25, request_kwargs=None, session=None)[source]
Create a Web3 instance with multi-provider support.
Create a complex Web3 connection manager that
Supports fail-overs to different providers
Can have a special execution endpoint for MEV protection
HTTP providers are monkey-patched for faster uJSON reading
HTTP providers have middleware cleared and chain middleware installed
The configuration line is a whitespace separated list of URLs (spaces, newlines, etc.) using mini configuration language.
If any of the protocols have mev+ prefix like mev+https then this endpoint is used for the execution.
Example:
config = "mev+https://rpc.mevblocker.io https://polygon-rpc.com https://bsc-dataseed2.bnbchain.org" web3 = create_multi_provider_web3(config) assert get_provider_name(web3.get_fallback_provider()) == "polygon-rpc.com" assert len(web3.get_fallback_provider().providers) == 2 assert get_provider_name(web3.get_active_transact_provider()) == "rpc.mevblocker.io"
See
Configuring MEV protection and JSON-RPC fallback for details
- Parameters
configuration_line (str) – Configuration line from an environment variable, config file or similar.
fallback_sleep – Seconds between JSON-RPC call retries.
fallback_backoff – Sleep increase multiplier.
request_kwargs (Optional[Any]) –
Passed to HTTPProvider, arguments for
requests
library when doing HTTP requests.See
web3.HTTPProvider
for details.Example:
request_kwargs={"timeout": 10.0}
Use specific HTTP 1.1 session with
requests
.If not given create a default session manager with retry logic.
- Returns
Configured Web3 instance with multiple providers
- Return type