26 lines
831 B
Python
26 lines
831 B
Python
import json
|
|
import requests
|
|
from loguru import logger
|
|
from typing import Any, Optional, Dict
|
|
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}'
|
|
response = requests.get(url, headers=headers, params=params)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
|
|
# Check for error in the response
|
|
if data['status'] == '0':
|
|
logger.error(f"Error fetching ABI: {data.get('result')}")
|
|
return None
|
|
|
|
return json.loads(data['result'])
|
|
|
|
|
|
def load_config(path: str) -> dict:
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
return json.loads(f.read())
|