From 7bd73cae08c5f932508a07ff79ccb38bef0d56d7 Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 8 Jun 2024 14:27:18 -0400 Subject: [PATCH] add etherscan api key as optional parameter --- main.py | 3 ++- monitor.py | 4 ++-- util.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index de5f53b..0f0b58b 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,8 @@ async def main(): monitor = EventMonitor( config={ "infura_url": config['infura_url'], - "pool_address": config['pool_address'] + "pool_address": config['pool_address'], + "etherscan_key": config['etherscan_key'] }, queue=queue ) diff --git a/monitor.py b/monitor.py index 05b154d..beaf3d5 100644 --- a/monitor.py +++ b/monitor.py @@ -15,7 +15,7 @@ class EventMonitor: self.web3 = Web3(Web3.HTTPProvider(self.config['infura_url'])) pool_address = self.config['pool_address'] - pool_abi = fetch_abi(pool_address) + pool_abi = fetch_abi(pool_address, key=self.config['etherscan_key']) self.contract = self.web3.eth.contract( address=pool_address, abi=pool_abi @@ -37,7 +37,7 @@ class EventMonitor: def fetch_token_info(self, token_address): try: - token_abi = fetch_abi(token_address) + token_abi = fetch_abi(token_address, key=self.config['etherscan_key']) except Exception as err: logger.warning(f"Failed to fetch info for {token_address}: {err}") return { diff --git a/util.py b/util.py index aa6a393..0e199f0 100644 --- a/util.py +++ b/util.py @@ -6,8 +6,8 @@ from web3.types import ChecksumAddress def fetch_abi(address: ChecksumAddress, headers: Optional[Dict[str, Any]] = None, - params: Optional[Dict[str, Any]] = None) -> Optional[Dict[str, Any]]: - url = f'https://api.etherscan.io/api?module=contract&action=getabi&address={address}' + params: Optional[Dict[str, Any]] = None, key: Optional[str] = None) -> Optional[Dict[str, Any]]: + url = f'https://api.etherscan.io/api?module=contract&action=getabi&address={address}&apikey={key}' response = requests.get(url, headers=headers, params=params) response.raise_for_status() data = response.json()