diff --git a/app/app/local.env b/app/app/local.env index 5cf4529082a..686cbaaf75c 100644 --- a/app/app/local.env +++ b/app/app/local.env @@ -31,3 +31,5 @@ GITHUB_API_TOKEN= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_APP_NAME= + +INFURA_USE_V3=True diff --git a/app/app/settings.py b/app/app/settings.py index 3384f87e9a3..4aceca44499 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -659,6 +659,8 @@ # Web3 WEB3_HTTP_PROVIDER = env('WEB3_HTTP_PROVIDER', default='https://rinkeby.infura.io') +INFURA_USE_V3 = env.bool('INFURA_USE_V3', False) +INFURA_V3_PROJECT_ID = env('INFURA_V3_PROJECT_ID', default='1e0a90928efe4bb78bb1eeceb8aacc27') # COLO Coin COLO_ACCOUNT_ADDRESS = env('COLO_ACCOUNT_ADDRESS', default='') # TODO diff --git a/app/dashboard/tests/test_dashboard_utils.py b/app/dashboard/tests/test_dashboard_utils.py index 2618f0c75ca..b0e86198bfe 100644 --- a/app/dashboard/tests/test_dashboard_utils.py +++ b/app/dashboard/tests/test_dashboard_utils.py @@ -19,6 +19,7 @@ """ from unittest.mock import patch +from django.conf import settings from django.test.client import RequestFactory from dashboard.utils import ( @@ -42,7 +43,10 @@ def test_get_web3(): assert isinstance(web3_provider, Web3) assert len(web3_provider.providers) == 1 assert isinstance(web3_provider.providers[0], HTTPProvider) - assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io' + if settings.INFURA_USE_V3: + assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io/v3/{settings.INFURA_V3_PROJECT_ID}' + else: + assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io' @staticmethod def test_get_bounty_contract(): diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index 0eefd30ac16..7d093eab3b4 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -261,9 +261,16 @@ def get_web3(network, sockets=False): """ if network in ['mainnet', 'rinkeby', 'ropsten']: if sockets: - provider = WebsocketProvider(f'wss://{network}.infura.io/ws') + if settings.INFURA_USE_V3: + provider = WebsocketProvider(f'wss://{network}.infura.io/ws/v3/{settings.INFURA_V3_PROJECT_ID}') + else: + provider = WebsocketProvider(f'wss://{network}.infura.io/ws') else: - provider = HTTPProvider(f'https://{network}.infura.io') + if settings.INFURA_USE_V3: + provider = HTTPProvider(f'https://{network}.infura.io/v3/{settings.INFURA_V3_PROJECT_ID}') + else: + provider = HTTPProvider(f'https://{network}.infura.io') + w3 = Web3(provider) if network == 'rinkeby': w3.middleware_stack.inject(geth_poa_middleware, layer=0) diff --git a/docs/ENVIRONMENT_VARIABLES.md b/docs/ENVIRONMENT_VARIABLES.md index 8046cb1b538..bc2ad16349c 100644 --- a/docs/ENVIRONMENT_VARIABLES.md +++ b/docs/ENVIRONMENT_VARIABLES.md @@ -118,6 +118,8 @@ The below environment variables are useful for overwriting [Django Silk](https:/ | Variable | Description | Type | Default | | --- | --- | --- | --- | | WEB3_HTTP_PROVIDER | The Web3 HTTP provider URI to be used. | `str` | https://rinkeby.infura.io | +| INFURA_USE_V3 | Use new API | `bool` | False | +| INFURA_V3_PROJECT_ID | Infura Project ID | `str` | 1e0a90928efe4bb78bb1eeceb8aacc27 | ## VSCode Remote Debugging