start erc-20 sandbox stuff

This commit is contained in:
agatha 2024-06-03 17:23:53 -04:00
parent fb4d0eff3f
commit 9e5adc2ef4
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,37 @@
"""
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()

View File

@ -0,0 +1,3 @@
requests
loguru
web3