start_rpc_proxy
Documentation for eth_defi.provider.rpc_proxy.start_rpc_proxy function.
- start_rpc_proxy(rpc_urls, port=None, config=None, **kwargs)
Start a JSON-RPC failover proxy on a background thread.
The proxy listens on
localhostand forwards incoming JSON-RPC POST requests to the given upstream RPC URLs with automatic failover, retry, and statistics collection.- Parameters
rpc_urls (list[str]) – Upstream RPC endpoint URLs to cycle through. At least one URL is required.
Local port to bind on
127.0.0.1.If
None(the default), the server binds to port0which tells the operating system to assign a free ephemeral port atomically. The actual port is read back from the socket after binding and stored inRPCProxy.port. This avoids the TOCTOU race condition that occurs withfind_free_port(): that function checks availability viaconnect(), but under heavy parallel test execution (pytest -n auto) another process can grab the same port between the check and thebind()call, resulting inOSError: [Errno 98] Address already in use.Pass an explicit port number only when you need a deterministic address (e.g. for debugging or firewall rules).
config (Optional[eth_defi.provider.rpc_proxy.RPCProxyConfig]) – Proxy configuration. If
None, a defaultRPCProxyConfigis used. Individual fields can be overridden via**kwargs.kwargs – Override individual
RPCProxyConfigfields. For examplestart_rpc_proxy(urls, timeout=10.0)is equivalent tostart_rpc_proxy(urls, config=RPCProxyConfig(timeout=10.0)). When bothconfigandkwargsare provided,kwargswin.
- Returns
A running
RPCProxyinstance. CallRPCProxy.close()when done.- Return type