start erc-20 sandbox stuff
This commit is contained in:
parent
fb4d0eff3f
commit
9e5adc2ef4
37
contract-monitoring/main.py
Normal file
37
contract-monitoring/main.py
Normal 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()
|
3
contract-monitoring/requirements.txt
Normal file
3
contract-monitoring/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
requests
|
||||||
|
loguru
|
||||||
|
web3
|
Loading…
Reference in New Issue
Block a user