use fallback ERC-20 ABI
This commit is contained in:
parent
8bd83a28c8
commit
c85b3ea38d
4
main.py
4
main.py
@ -11,7 +11,8 @@ from util import load_config
|
||||
|
||||
|
||||
def init_logger():
|
||||
logger.add(sys.stdout, level="DEBUG")
|
||||
logger.remove()
|
||||
logger.add(sys.stdout, level="INFO")
|
||||
|
||||
|
||||
async def main():
|
||||
@ -47,4 +48,5 @@ async def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_logger()
|
||||
asyncio.get_event_loop().run_until_complete(main())
|
||||
|
33
util.py
33
util.py
@ -4,6 +4,36 @@ from loguru import logger
|
||||
from typing import Any, Optional, Dict
|
||||
from web3.types import ChecksumAddress
|
||||
|
||||
STANDARD_ERC20_ABI = [
|
||||
{
|
||||
"constant": True,
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [{"name": "", "type": "string"}],
|
||||
"payable": False,
|
||||
"stateMutability": "view",
|
||||
"type": "function",
|
||||
},
|
||||
{
|
||||
"constant": True,
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [{"name": "", "type": "string"}],
|
||||
"payable": False,
|
||||
"stateMutability": "view",
|
||||
"type": "function",
|
||||
},
|
||||
{
|
||||
"constant": True,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [{"name": "", "type": "uint256"}],
|
||||
"payable": False,
|
||||
"stateMutability": "view",
|
||||
"type": "function",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def fetch_abi(address: ChecksumAddress, headers: Optional[Dict[str, Any]] = None,
|
||||
params: Optional[Dict[str, Any]] = None, key: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
||||
@ -15,7 +45,8 @@ def fetch_abi(address: ChecksumAddress, headers: Optional[Dict[str, Any]] = None
|
||||
# Check for error in the response
|
||||
if data['status'] == '0':
|
||||
logger.error(f"Error fetching ABI: {data.get('result')}")
|
||||
return None
|
||||
logger.warning(f"Using fallback ABI.")
|
||||
return STANDARD_ERC20_ABI
|
||||
|
||||
return json.loads(data['result'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user