Skip to content

Commit

Permalink
Add multi RPC documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Aug 3, 2023
1 parent e21a2d7 commit f408055
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Example tutorials
live-swap
aave-v3-interest-analysis
slippage-and-price-impact
multi-rpc-configuration

`For more examples, browse tests folder on Github <https://github.com/tradingstrategy-ai/web3-ethereum-defi/tree/master/tests>`__.
You can also search function names in `the repository <https://github.com/tradingstrategy-ai/web3-ethereum-defi/>`__
Expand Down
36 changes: 36 additions & 0 deletions docs/source/tutorials/multi-rpc-configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. _multi rpc:

Configuring multiple RPC endpoints
==================================

The package supports creating :py:class:`eth_defi.provider.multi_provider.MultiProviderWeb3`
instances of :py:class:`Web3` core connector.

These instances support multiple JSON-RPC providers, mainly

- Automatic fallback to another JSON-RPC provider when one fails

- Using `Malicious Extractable Value protection <https://tradingstrategy.ai/glossary/mev>`__
with a special endpoints when broadcasting a transaction

Configuring
-----------

The multi RPC endpoints can be created with :py:func:`eth_defi.provider.multi_provider.create_multi_provider_web3`.

Instead of giving a single RPC endpoint URL, you give a list URLs.

- List can be newline separated or space separated

- For MEV protection endpoint, you prefix your URL with `mev+`

Example:

.. code-block::
# Uses MEVblocker.io to broadcast transactions
# and two separate nodes for reading blockchain data
config = "mev+https://rpc.mevblocker.io https://myethereumnode1.example.com https://fallback.example.com"
web3 = create_multi_provider_web3(config)
16 changes: 14 additions & 2 deletions eth_defi/provider/multi_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Configuring and managing multiple JSON-RPC provider connections."""
"""Configuring and managing multiple JSON-RPC provider connections.
See :ref:`multi rpc` for details.
"""

import logging
from typing import List
Expand Down Expand Up @@ -28,7 +31,12 @@ class MultiProviderWeb3(Web3):
- There might be several providers for reading on-chain data
See :py:func:`create_multi_provider_web3`
See
- :ref:`multi rpc` for details
- :py:func:`create_multi_provider_web3`
"""

def get_active_transact_provider(self) -> NamedProvider:
Expand Down Expand Up @@ -111,6 +119,10 @@ def create_multi_provider_web3(
assert len(web3.get_fallback_provider().providers) == 2
assert get_provider_name(web3.get_active_transact_provider()) == "rpc.mevblocker.io"
See
- - :ref:`multi rpc` for details
:param configuration_line:
Configuration line from an environment variable, config file or similar.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "web3-ethereum-defi"
version = "0.22.1"
version = "0.22.2"
description = "Python library for Uniswap, Aave, ChainLink, Enzyme and other protocols on BNB Chain, Polygon, Ethereum and other blockchains"
authors = ["Mikko Ohtamaa <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit f408055

Please sign in to comment.