def get_contract_abi(contract_address): my_contract = Contract(address=contract_address,api_key=setting.API_KEY) my_contract.PREFIX =setting.ETHSCAN_API_PREFIX try: res = my_contract.get_abi() except: res = None return res
class contracts(): def __init__(self, key, address): # Setup api for single address self.key = key self.address = address self.api = Contract(address=address, api_key=key) def get_contract(self): # cannot transfer to DataFrame return self.api.get_abi() def get_sourcecode(self): sourcecode = self.api.get_sourcecode() return pd.DataFrame(sourcecode)
def get_abi_from_address(address): """ Return ABI for address """ api_key = get_etherscan_api_key() api = Contract(address=address, api_key=api_key) try: abstract_bi = api.get_abi() except: logger.warning('Empty Response. Try again later.') return None else: if not abstract_bi: return None return abstract_bi
def load_contract(_contract, _eth_connect): key = 'WXPQDYFIT982E3GPJR9JEHXHNYRADB34BN' file_name = 'abi/' + _contract + '.json' if not os.path.isfile(file_name): api = Contract(address=_contract, api_key=key) try: _this_abi = api.get_abi() print("Downloading missing abi for ", _contract) json.dump(_this_abi, open(file_name, "w"), indent=4) #Output dictionary to minute file except Exception: pass else: _this_abi = json.load(open(file_name, 'r')) return _eth_connect.eth.contract(_contract, abi=_this_abi).functions
def main(): if len(sys.argv) < 2: print("usage: " + os.path.basename(__file__) + " Smart Contract Address") print( "Smart Contracts can be found on ERC20 token pages and where they are used" ) sys.exit(1) else: wallet_addy = str(sys.argv[1]) address = wallet_addy api = Contract(address=wallet_addy, api_key=key) abi = api.get_abi() # abi = int(abi) print(abi)
from etherscan.contracts import Contract import json with open('./key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359' api = Contract(address=address, api_key=key) abi = api.get_abi() print(abi) sourcecode = api.get_sourcecode() # TODO: make this return something pretty print(sourcecode[0]['SourceCode'])
def get_contract_abi(): api = Contract(address=ADDRESS, api_key=ether_key) abi = api.get_abi() return abi
def get_contract_abi(contract_address=CONTRACT_ADDRESS, etherscan_api_key=ETHERSCAN_API_KEY): es_api = EsContract(address=contract_address, api_key=etherscan_api_key) abi = json.loads(es_api.get_abi()) return abi
from etherscan.contracts import Contract import json with open('../../api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359' api = Contract(address=address, api_key=key) abi = api.get_abi() print(abi)
api = EtherscanAPI() API_KEY = api.key api._create_data_folder(DATA_DIR) def save_json(data, filename, save): if save: filepath = os.path.join(DATA_DIR, filename) with open(filepath, 'w') as json_file: json.dump(data, json_file, indent=4) def save_sol(data, filename, save): if save: filepath = os.path.join(DATA_DIR, filename) with open(filepath, 'w') as sol_file: sol_file.write(data) if __name__=='__main__': test_address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359' contract = Contract(address=test_address, api_key=API_KEY) abi = contract.get_abi() js = json.loads(abi) abi_filename = f'abi-address-{test_address}.json' save_json(js, abi_filename, save=True) sourcecode = contract.get_sourcecode() sourcecode_filename = f'contract-sourcecode-address-{test_address}.sol' save_sol(sourcecode[0]['SourceCode'], sourcecode_filename, save=True)