38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
|
"""
|
||
|
ERC-20 monitoring sandbox
|
||
|
|
||
|
An exercise exploring ABIs and chain events
|
||
|
"""
|
||
|
import requests
|
||
|
from typing import Any, Optional, Dict
|
||
|
|
||
|
JENNER_ADDRESS = '0x482702745260ffd69fc19943f70cffe2cacd70e9'
|
||
|
|
||
|
|
||
|
def fetch_abi(
|
||
|
address: str,
|
||
|
headers: Optional[Dict[str, Any]] = None,
|
||
|
params: Optional[Dict[str, Any]] = None
|
||
|
) -> Optional[Dict[str, Any]]:
|
||
|
# TODO: Ensure it is a well-formed address
|
||
|
# TODO: Check for errors, such as a "status" key set to 0
|
||
|
url = f'https://api.etherscan.io/api?module=contract&action=getabi&address={address}'
|
||
|
try:
|
||
|
response = requests.get(url, headers=headers, params=params)
|
||
|
response.raise_for_status()
|
||
|
return response.json()
|
||
|
except requests.exceptions.RequestException as err:
|
||
|
print(f'Error during the request: {err}')
|
||
|
return None
|
||
|
except ValueError as err:
|
||
|
print(f'Error parsing JSON: {err}')
|
||
|
|
||
|
|
||
|
def main():
|
||
|
jenner_abi = fetch_abi(JENNER_ADDRESS)
|
||
|
print(jenner_abi)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|