diff --git a/ape_infura/provider.py b/ape_infura/provider.py index 9a49d19..ec1a9da 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -11,7 +11,10 @@ from web3.exceptions import ContractLogicError as Web3ContractLogicError from web3.exceptions import ExtraDataLengthError from web3.gas_strategies.rpc import rpc_gas_price_strategy -from web3.middleware import geth_poa_middleware +try: + from web3.middleware import ExtraDataToPOAMiddleware # type: ignore +except ImportError: + from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore from web3.middleware.validation import MAX_EXTRADATA_LENGTH _API_KEY_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID", "WEB3_INFURA_API_KEY") @@ -135,7 +138,7 @@ def connect(self): self._web3 = _create_web3(http_provider) if self._needs_poa_middleware: - self._web3.middleware_onion.inject(geth_poa_middleware, layer=0) + self._web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0) self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy) diff --git a/setup.py b/setup.py index 4fcae5a..20e4955 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,8 @@ include_package_data=True, install_requires=[ "eth-ape>=0.8.1,<0.9", + "web3>=7.6.0,<8", + "requests>=2.32.3,<3", ], python_requires=">=3.9,<4", extras_require=extras_require, diff --git a/tests/test_provider.py b/tests/test_provider.py index a578f8c..e8d6506 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -4,7 +4,10 @@ import websocket # type: ignore from ape import networks from web3.exceptions import ExtraDataLengthError -from web3.middleware import geth_poa_middleware +try: + from web3.middleware import ExtraDataToPOAMiddleware # type: ignore +except ImportError: + from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura, _get_session @@ -116,7 +119,7 @@ def test_dynamic_poa_check(mocker): patch = mocker.patch("ape_infura.provider._create_web3") patch.return_value = mock_web3 infura.connect() - mock_web3.middleware_onion.inject.assert_called_once_with(geth_poa_middleware, layer=0) + mock_web3.middleware_onion.inject.assert_called_once_with(ExtraDataToPOAMiddleware, layer=0) def test_api_secret():