def get_byte_code(self): ''' get byte code from api call 'https://api.etherscan.io/api?module=proxy&action=eth_getCode&address=0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c&tag=latest&apikey=YourApiKeyToken' Parameters : contract_addr return : file of byte code ''' target_url = 'https://api.etherscan.io/api?module=proxy&action=eth_getCode&address=' + str(self.contract_addr) result = crawl_url_by_get(target_url, proxy=None, enable_proxy=True) # print result, type(result) with open(self.base_dir + '/byte_code', 'w') as bc: bc.write(result)
def get_contract_abi(self): ''' get contract ABI from api call 'https://api.etherscan.io/api?module=contract&action=getabi&address=' Parameters : contract_addr return : file of contract abi ''' target_url = 'https://api.etherscan.io/api?module=contract&action=getabi'\ + '&address=' + str(self.contract_addr)\ + '&apikey=' + str(self.api_key) result = crawl_url_by_get(target_url, proxy=None, enable_proxy=True) # print result, type(result) with open(self.base_dir + '/contract_abi', 'w') as ca: ca.write(result)
def get_op_code(self): ''' get op codes from api call 'https://etherscan.io/api?module=opcode&action=getopcode&address=0xDa65eed883A48301D0EcF37465f135A7a0C9d978' Parameters : contract_addr return : file of op code ''' target_url = 'https://etherscan.io/api?module=opcode&action=getopcode&address=' + str(self.contract_addr) result = crawl_url_by_get(target_url, proxy=None, enable_proxy=True) # print result, type(result) with open(self.base_dir + '/op_code', 'w') as oc: oc.write(result) parse_op_code = json.loads(result)['result'].split('<br>') # print parse_op_code, type(parse_op_code) with open(self.base_dir + '/parse_op_code', 'w') as poc: for e in parse_op_code: poc.write(e + '\n')
def get_parse_html(self, write2file=False): ''' get details of a given smart contract Parameters : contract_addr, smart contract address return : parse_html ''' ''' if os.path.exists(self.base_dir + '/parse.html'): with open(self.base_dir + '/parse.html', 'r') as pt: raw_html = pt.read() parse_html = etree.HTML(raw_html) return parse_html ''' base_url = 'https://etherscan.io/address/' target_url = str(base_url) + str(self.contract_addr) + str('#code') raw_html = crawl_url_by_get(target_url, proxy=None) parse_html = etree.HTML(raw_html) if write2file: with open(self.base_dir + '/parse.html', 'w') as parse: parse.write(etree.tostring(parse_html)) return parse_html