Exemplo n.º 1
0
def get_contract_from_blockchain(address):
    key = get_api_key()
    api = Contract(address=address, api_key=key)
    sourcecode = api.get_sourcecode()

    assert len(sourcecode) == 1, f"no results found for {address}"
    assert len(sourcecode[0]["SourceCode"]) > 0, f"no sourcecode found for {address}"

    if sourcecode[0]["SourceCode"][0] == "{":
        # Multiple files
        file_mapping = {}
        src_path = f"{contract_dir}/contract_{address}/"
        if not os.path.exists(src_path):
            os.makedirs(src_path)
        src = sourcecode[0]["SourceCode"][1:-1]
        src = json.loads(src)
        for filepath, file in src["sources"].items():
            filename = os.path.basename(filepath)
            file_mapping[filepath] = filename
            with open(f"{src_path}{filename}", "w") as f:
                f.write(file["content"])
        # save the mappings
        with open(os.path.join(src_path, ".mapping"), "w+") as f:
            f.write(json.dumps(file_mapping))
    else:
        # Multiple files
        src_path = f"{contract_dir}/contract_{address}.sol"
        with open(src_path, "w") as c_file:
            c_file.write(sourcecode[0]["SourceCode"])

    return src_path, sourcecode[0]
Exemplo n.º 2
0
def get_contract_from_blockchain(address, key_file=None):

    key = get_api_key(key_file)
    api = Contract(address=address, api_key=key)
    sourcecode = api.get_sourcecode()
    with open(contract_dir, "w") as contract_file:
        contract_file.write(sourcecode[0]['SourceCode'])

    return contract_dir
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def get_sourcecode_from_address(address):
    """
    Return sourcecode for address

    See: https://git.io/fjbQW
         https://cloud.google.com/docs/authentication/getting-started
         https://sebs.github.io/etherscan-api/
    """
    api_key = get_etherscan_api_key()
    api = Contract(address=address,
                   api_key=api_key)
    try:
        sourcecode = api.get_sourcecode()
    except:
        logger.warning('Empty Response. Try again later.')
        return None
    else:
        if not sourcecode[0]['SourceCode']:
            return None
        if sourcecode[0]['ABI'] == 'Contract source code not verified':
            return None
        return sourcecode
Exemplo n.º 9
0
def get_contract_abi():
    api = Contract(address=ADDRESS, api_key=ether_key)
    abi = api.get_abi()
    return abi
Exemplo n.º 10
0
from etherscan.contracts import Contract
import json
import pandas as pd

with open(
        'C:/Yiru Xiong-Professional/实习/CryptoAlgoWheel/S1/task3/api_key.json',
        mode='r') as key_file:
    key = json.loads(key_file.read())['key']
address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359'
api = Contract(address=address, api_key=key)


def get_abi():
    abi = api.get_abi()
    text_file = open("S1_task3_contracts_abi_text.txt", "w")
    n = text_file.write(abi)
    text_file.close()


#get_abi()


def get_sourcecode():
    sourcecode = api.get_sourcecode()
    text_file = open("S1_tsak3_contracts_sourcecode_text.txt", "w")
    n = text_file.write(sourcecode[0]['SourceCode'])
    text_file.close()


#get_sourcecode()
Exemplo n.º 11
0
 def get_contract_source(self, address):
     api = Contract(address=address, api_key=self.api_key)
     sourcecode = api.get_sourcecode()
     return sourcecode[0]['SourceCode']
Exemplo n.º 12
0
 def get_resource_code(self, sc_addr):
     api = Contract(address=str(sc_addr), api_key=self.key)
     sourcecode = api.get_sourcecode()
     return sourcecode[0]['SourceCode']
Exemplo n.º 13
0
 def __init__(self, key, address):
     # Setup api for single address
     self.key = key
     self.address = address
     self.api = Contract(address=address, api_key=key)
Exemplo n.º 14
0
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
Exemplo n.º 15
0
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)
response_jsonify = etherscan_response.json()

total_supply_stasis = (int(response_jsonify.get("result"))) / 100
print(
    f'As per Etherscan, Stasis EURS Token Total Supply: {maybe_blue + str({str(total_supply_stasis)[:-2]}) + end_formatting} \n'
)

print(
    f'The discrepancy between the latest daily statement (Banks) and the total coin supply on the blockchain (Ethereum) is {okay_green + "€ " + str(abs(total_supply_stasis - total_bankstatement_balance)) + end_formatting}\n'
)
print(
    f'The discrepancy between the latest weekky verification (BDO) and the total coin supply on the blockchain (Ethereum) is {okay_green + "€ " + str(abs(total_supply_stasis - total_bdo_balance)) + end_formatting}\n'
)

#get solidity source code for Stasis' token contract and checks sha-256 hash
api = Contract(address=token_contract_address, api_key=etherscan_api_key)
sourcecode = api.get_sourcecode()
solidity_state = sourcecode[0]['SourceCode']
sol_hash = hashlib.sha256(solidity_state.encode('utf-8')).hexdigest()
print(
    f'Sha-256 Hash of Stasis Solidity Contract is: {dirty_yellow + sol_hash + end_formatting}\n'
)
#print (solidity_state)

#uses coincmarketcap's free keys to retrive information about stasis from all new pro api
stasis_cmc_url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?id=2989"
headers = {'X-CMC_PRO_API_KEY': '6ab59890-e6c8-4f77-830a-ae6142e34a7c'}

r = requests.get(stasis_cmc_url, headers=headers)
cmc_jsonified = r.json()
pretty_print_cmc = json.dumps(cmc_jsonified, indent=2)
Exemplo n.º 17
0
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)
sourcecode = api.get_sourcecode()
# TODO: make this return something pretty
print(sourcecode[0]['SourceCode'])
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)