Skip to content

Commit

Permalink
Allow setting Node URL as HTTP Provider (#76)
Browse files Browse the repository at this point in the history
This'll allow the user to specify any node provider instead of just
using Infura
  • Loading branch information
ahhda authored Oct 9, 2023
1 parent f6128af commit 2290bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Install the following libraries as dependencies. <br>
pip install python-dotenv


To test either of the components, create a `.env` file in the root directory (ebbo) and set variables `ETHERSCAN_KEY` and `INFURA_KEY` as string values from [Etherscan API Key](https://etherscan.io/myapikey) in your profile and Infura once you have an account created one. You will also need a `DUNE_KEY` for running the historical data test. <br>
To test either of the components, create a `.env` file in the root directory (ebbo) and set variables `ETHERSCAN_KEY` and `INFURA_KEY` as string values from [Etherscan API Key](https://etherscan.io/myapikey) in your profile and Infura once you have an account created one. You can also set `NODE_URL` instead of `INFURA_KEY` if you are using a different RPC provider. You will also need a `DUNE_KEY` for running the historical data test. <br>
Sample `.env` structure:

INFURA_KEY = 'string key here'
Expand Down
7 changes: 5 additions & 2 deletions src/apis/web3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class Web3API:

def __init__(self) -> None:
load_dotenv()
infura_key = getenv("INFURA_KEY")
self.url = f"https://mainnet.infura.io/v3/{infura_key}"
if getenv("NODE_URL"):
self.url = getenv("NODE_URL")
else:
infura_key = getenv("INFURA_KEY")
self.url = f"https://mainnet.infura.io/v3/{infura_key}"
self.web_3 = Web3(Web3.HTTPProvider(self.url))
self.contract = self.web_3.eth.contract(
address=Address(HexBytes(SETTLEMENT_CONTRACT_ADDRESS)), abi=gpv2_settlement
Expand Down

0 comments on commit 2290bf7

Please sign in to comment.