Skip to content

Web3py HTTPProvider that makes it easy to switch between different Ethereum nodes. To make sure the application will be ok if some of the nodes are down.

License

Notifications You must be signed in to change notification settings

lidofinance/web3py-multi-http-provider

Repository files navigation

Lido Web3 Multi Provider

Code style: black License: MIT

Provider that accepts multiple endpoints.

Install

$ pip install web3-multi-provider

or

$ poetry add web3-multi-provider

Usage

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')

MultiProvider

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.

FallbackProvider

This provider sends requests to the all endpoints in the sequence until response received or endpoints list exhausted.

AsyncMultiProvider and AsyncFallbackProvider

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/...',
]))

For developers

  1. poetry install - to install deps
  2. pre-commit install - to install pre-commit hooks

Tests

poetry run pytest tests

About

Web3py HTTPProvider that makes it easy to switch between different Ethereum nodes. To make sure the application will be ok if some of the nodes are down.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages