load_contract_abi

Function

def load_contract_abi(address):
    try:
        abi = json.load(open("./data/abi/{}.json".format(address)))
    except FileNotFoundError:
        try:
            abi = get_abi_from_blockscout(address)
        except Exception as e:
            logging.debug(e)
            raise FileNotFoundError("Download a copy of the abi from Blockscout to this folder")
        else:
            if abi:
                open("./data/abi/{}.json".format(address), 'w').write(json.dumps(abi, indent=4))
            else:
                raise FileNotFoundError("No abi found for this contract")
    return abi

Description

  • Tries to load the ABI from cache folder

  • Fallback to trying to pull from Blockscout

  • If the ABI is returned from Blockscout, save it to the cache folder

  • Return the ABI as JSON