예제 #1
0
def main():
    with open('../api_key.json', mode='r') as key_file:
        key = json.loads(key_file.read())['key']
    
    # get steven's contract initialization input data as a reference
    api = Proxies(api_key=key)
    transaction_1 = api.get_transaction_by_hash(
    	tx_hash='0x5920ad6d2c1caa27dae2e85b4764a28c7665d8f4ecfc17150c0abd9f26cb2ca4')
    target_input_1 = transaction_1['input']
    transaction_2 = api.get_transaction_by_hash(
    	tx_hash='0x881bd88aac40ba6f49e7e6130e7bafc154a9e918b6f792742ff10cf731309cce')
    target_input_2 = transaction_2['input']
    
    target_input = longestSubstringFinder(target_input_1, target_input_2)
    # Search over all Tx within all blocks between 6pm and 7pm local time
    #block = api.get_block_by_number(3638953)
    #print(block.keys())
    
    hash_list = []
    block_number_all = list(range(3626750,3626760))
    for block_number in block_number_all:
        block = api.get_block_by_number(block_number)
        for transaction in block['transactions']:
            if transaction['input'][0:5960] == target_input:
                hash_list.append(transaction['hash'])
            
    print (hash_list)
예제 #2
0
 def test_get_most_recent_block(self):
     api = Proxies(api_key=API_KEY)
     # currently raises an exception even though it should not, see:
     # https://github.com/corpetty/py-etherscan-api/issues/32
     most_recent = int(api.get_most_recent_block(), 16)
     print(most_recent)
     p = re.compile('^[0-9]{7}$')
     self.assertTrue(p.match(str(most_recent)))
예제 #3
0
class proxies():
    def __init__(self, key):
        self.key = key
        self.api = Proxies(api_key=key)

    '''
    def gas_price(self):
        return self.api.gas_price()
    '''

    def get_block(self, number):
        block_number = self.api.get_block_by_number(block_number=number)
        return pd.DataFrame.from_dict(block_number, orient='index')

    def tx_count(self, number):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=number)
        tx_count = [int(tx_count, 16)]
        return pd.DataFrame(tx_count, ['block_transaction_count_by_number'])

    '''
    def get_code(self, address):
 Error: Exception has occurred: AttributeError. 'Proxies' object has no attribute 'get_code'
        return self.api.get_code(address = address)
    '''

    def get_recent_block(self):
        block = self.api.get_most_recent_block()
        block = [int(block, 16)]
        return pd.DataFrame(block, columns=['most recent block'])

    '''
    def value(self):
   Error: no attribute
        return self.api.get_storage_at('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', 0x0)
    '''

    def Transactions(self, number, index):
        return self.api.get_transaction_by_blocknumber_index(
            block_number=number, index=index)

    def transaction_hash(self, TX_HASH):
        transaction = self.api.get_transaction_by_hash(tx_hash=TX_HASH)
        return transaction

    def transaction_count(self, address):
        count = self.api.get_transaction_count(address=address)
        count = [int(count, 16)]
        return count

    def transaction_receipt(self, TX_HASH):
        receipt = self.api.get_transaction_receipt(tx_hash=TX_HASH)
        return receipt

    def uncle(self, number, index):
        uncel = self.api.get_uncle_by_blocknumber_index(block_number=number,
                                                        index=index)
        return uncel
class Proxies_usage:
    def __init__(self, key):
        self.api_key = key
        self.api = Proxies(api_key=key)

    #### get information about a block by block number (and save the result in a JSON file)
    def block_info_by_number(self, block_number):
        block = self.api.get_block_by_number(block_number)
        with open("./block_info_by_number.json", "w") as json_file:
            json.dump(block, json_file)

    #### get the number of transactions in a block matching the given block number
    def block_trans_count_by_number(self, block_number):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=block_number)
        return int(tx_count, 16)

    #### get the number of most recent block
    def most_recent_block(self):
        block = self.api.get_most_recent_block()
        return int(block, 16)

    #### get information about a transaction by block number and transaction index position (and save to a csv file)
    def trans_info_by_number_index(self, block_number, index):
        transaction = self.api.get_transaction_by_blocknumber_index(
            block_number=block_number, index=index)
        transaction = pd.DataFrame(transaction, index=[0])
        transaction.to_csv("./transaction_info_by_number_index.csv",
                           index=False)

    #### get the informationa bout a transaction by transaction hash (and save to a csv file)
    def trans_info_by_hash(self, hash):
        transaction = self.api.get_transaction_by_hash(tx_hash=hash)
        transaction = pd.DataFrame(transaction, index=[0])
        transaction.to_csv("./transaction_info_by_hash.csv", index=False)

    #### get the number of transactions sent from an address
    def trans_count_from_addr(self, address):
        count = self.api.get_transaction_count(address)
        return int(count, 16)

    #### get (display) the receipt of a transaction by transaction hash
    def trans_receipt_by_hash(self, hash):
        receipt = self.api.get_transaction_receipt(hash)
        receipt = pd.DataFrame.from_dict(receipt, orient="index")
        display(receipt)

    #### get information about a uncle by block number
    def uncle_by_number_index(self, block_number, index="0x0"):
        uncles = self.api.get_uncle_by_blocknumber_index(
            block_number=block_number, index=index)
        return uncles["uncles"]
예제 #5
0
 def test_gas_price(self):
     api = Proxies(api_key=API_KEY)
     price = int(api.gas_price(), 16)
     print(price)
     p = re.compile('^[0-9]*$')
     self.assertTrue(p.match(str(price)))
예제 #6
0
 def test_get_code(self):
     api = Proxies(api_key=API_KEY)
     code_contents = api.get_code(CODE_ADDRESS)
     print(code_contents)
     self.assertEqual(code_contents, CODE_CONTENTS)
예제 #7
0
 def test_get_transaction_count(self):
     api = Proxies(api_key=API_KEY)
     tx_count = int(api.get_transaction_count(TX_ADDRESS), 16)
     print(tx_count)
     p = re.compile('^[0-9]*$')
     self.assertTrue(p.match(str(tx_count)))
예제 #8
0
 def test_get_transaction_by_hash(self):
     api = Proxies(api_key=API_KEY)
     tx = api.get_transaction_by_hash(TX_HASH)
     print(tx)
     self.assertEqual(tx['blockNumber'], hex(BLOCK_NUMBER))
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
tx_count = api.get_block_transaction_count_by_number(block_number='0x10FB78')
print(int(tx_count, 16))
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
block = api.get_most_recent_block()
print(int(block, 16))
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
uncles = api.get_uncle_by_blocknumber_index(block_number='0x210A9B',
                                            index='0x0')
print(uncles['uncles'])
예제 #12
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
value = api.get_storage_at('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', 0x0)
print(value)
예제 #13
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']
TX_HASH = '0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'
api = Proxies(api_key=key)
transaction = api.get_transaction_by_hash(tx_hash=TX_HASH)
print(transaction['hash'])
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
transaction = api.get_transaction_by_blocknumber_index(block_number='0x57b2cc',
                                                       index='0x2')
print(transaction['transactionIndex'])
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']
TX_HASH = '0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'
api = Proxies(api_key=key)
transaction = api.get_transaction_by_hash(
    tx_hash=TX_HASH)
print(transaction['hash'])
예제 #16
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
transaction = api.get_transaction_by_hash(
    tx_hash='0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'
)
print(transaction['hash'])
예제 #17
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
price = api.gas_price()
print(price)
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
block = api.get_block_by_number(5747732)
print(block['number'])
예제 #19
0
from etherscan.proxies import Proxies
import json

with open('api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
receipt = api.get_transaction_receipt(
    '0xb03d4625fd433ad05f036abdc895a1837a7d838ed39f970db69e7d832e41205d')

with open("get_transaction_receipt.json", "w") as outfile:
    json.dump(receipt, outfile)
예제 #20
0
 def test_get_block_transaction_count_by_number(self):
     api = Proxies(api_key=API_KEY)
     tx_count = api.get_block_transaction_count_by_number(BLOCK_NUMBER)
     print(tx_count)
     self.assertEqual(tx_count, hex(TX_COUNT))
예제 #21
0
from  etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']


api = Proxies(api_key=key)
tx_count = api.get_block_transaction_count_by_number(block_number='0x10FB78')
print(int(tx_count, 16))
예제 #22
0
 def test_get_transaction_by_blocknumber_index(self):
     api = Proxies(api_key=API_KEY)
     tx = api.get_transaction_by_blocknumber_index(BLOCK_NUMBER,
                                                   TX_INDEX)
     print(tx)
     self.assertEqual(tx['hash'], TX_HASH)
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
transaction = api.get_transaction_by_blocknumber_index(block_number='0x57b2cc',
                                                       index='0x2')
print(transaction['transactionIndex'])
예제 #24
0
 def test_get_transaction_receipt(self):
     api = Proxies(api_key=API_KEY)
     tx_receipt = api.get_transaction_receipt(TX_HASH)
     print(tx_receipt)
     self.assertEqual(tx_receipt['blockNumber'], hex(BLOCK_NUMBER))
예제 #25
0
class Proxy(EtherscanAPI):
    def __init__(self):
        super().__init__()
        self.api = Proxies(api_key=self.key)
        self._create_data_folder(DATA_DIR)

    # def gas_price(self):
    #     price = self.api.gas_price()
    #     return price

    def _save_json(self, 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 get_most_recent_block(self, save=False):
        block = self.api.get_most_recent_block()
        filename = f'most-recent-block.json'
        self._save_json(block, filename, save)
        return block

    def get_block_by_number(self, block_num, save=False):
        block = self.api.get_block_by_number(block_num)
        filename = f'block-{block_num}-data.json'
        self._save_json(block, filename, save)
        return block

    def get_uncle_by_blocknumber_index(self, block_num, index, save=False):
        uncles = self.api.get_uncle_by_blocknumber_index(
            block_number=block_num, index=index)
        filename = f'block-{block_num}-{index}-uncles-data.json'
        self._save_json(uncles, filename, save)
        return uncles

    def get_block_transaction_count_by_number(self, block_num, save=False):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=block_num)
        return int(tx_count, 16)

    def get_transaction_by_hash(self, tx_hash, save=False):
        transaction = self.api.get_transaction_by_hash(tx_hash=tx_hash)
        filename = f'transaction-data-of-hash-{tx_hash}.json'
        self._save_json(transaction, filename, save)
        return transaction

    def get_transaction_by_blocknumber_index(self,
                                             block_num,
                                             index,
                                             save=False):
        transaction = self.api.get_transaction_by_blocknumber_index(
            block_number=block_num, index=index)
        filename = f'transaction-data-of-block-{block_num}.json'
        self._save_json(transaction, filename, save)
        return transaction

    def get_transaction_count(self, address, save=False):
        count = self.api.get_transaction_count(address)
        return int(count, 16)

    def get_transaction_receipt(self, tx_hash, save=False):
        receipt = self.api.get_transaction_receipt(tx_hash)
        filename = f'transaction-recepit-of-hash-{tx_hash}.json'
        self._save_json(receipt, filename, save)
        return receipt
예제 #26
0
 def test_get_storage_at(self):
     api = Proxies(api_key=API_KEY)
     storage_contents = api.get_storage_at(STORAGE_ADDRESS, STORAGE_POS)
     print(storage_contents)
     self.assertEqual(storage_contents, STORAGE_CONTENTS)
예제 #27
0
 def __init__(self):
     super().__init__()
     self.api = Proxies(api_key=self.key)
     self._create_data_folder(DATA_DIR)
예제 #28
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
code = api.get_code('0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c')
print(code)
예제 #29
0
from etherscan.proxies import Proxies
import json

with open('./key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)

# get price
price = api.GAS_PRICE()
print(price)

# get blocks by number
block = api.get_block_by_number(5747732)
print(block['number'])

# get block transaction count by number
tx_count = api.get_block_transaction_count_by_number(block_number='0x10FB78')
print(int(tx_count, 16))

# get most recent block
block = api.get_most_recent_block()
print(int(block, 16))

# get transactions
transaction = api.get_transaction_by_blocknumber_index(block_number='0x57b2cc',
                                                       index='0x2')
print(transaction['transactionIndex'])

# get transactions by hash
TX_HASH = '0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'
예제 #30
0
# Contracts

address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359'
api = Contract(address=address, api_key=key)

abi = api.get_abi()
sourcecode = api.get_sourcecode()

# Proxies

number = 10453272
block_numb = '0x9f8118'
address = '0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c'
TX_HASH = '0xb03d4625fd433ad05f036abdc895a1837a7d838ed39f970db69e7d832e41205d'
index = '0x0'
api = Proxies(api_key=key)

price = api.gas_price()
block = api.get_block_by_number(number)
tx_count = api.get_block_transaction_count_by_number(block_number=block_numb)
code = api.get_code(address)
block0 = api.get_most_recent_block()
value = api.get_storage_at(address, 0x0)
transaction = api.get_transaction_by_blocknumber_index(block_number=block_numb,
                                                       index=index)
transaction = api.get_transaction_by_hash(tx_hash=TX_HASH)
count = api.get_transaction_count(address)
receipt = api.get_transaction_receipt(TX_HASH)
uncles = api.get_uncle_by_blocknumber_index(block_number=block_numb,
                                            index=index)
예제 #31
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
count = api.get_transaction_count('0x6E2446aCfcec11CC4a60f36aFA061a9ba81aF7e0')
print(int(count, 16))
예제 #32
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
uncles = api.get_uncle_by_blocknumber_index(block_number='0x210A9B',
                                            index='0x0')
print(uncles['uncles'])
예제 #33
0
def test_get_most_recent_block():
    api = Proxies(api_key=API_KEY)
    most_recent = int(api.get_most_recent_block(), 16)
    print(most_recent)
    p = re.compile('^[0-9]{7}$')
    assert (p.match(str(most_recent)))
예제 #34
0
 def test_get_most_recent_block(self):
     api = Proxies(api_key=API_KEY)
     most_recent = int(api.get_most_recent_block(), 16)
     print(most_recent)
     p = re.compile('^[0-9]{7}$')
     self.assertTrue(p.match(str(most_recent)))
예제 #35
0
 def test_get_block_by_number(self):
     api = Proxies(api_key=API_KEY)
     block = api.get_block_by_number(BLOCK_NUMBER)
     print(block)
     self.assertEqual(block['difficulty'], hex(BLOCK_DIFFICULTY))
 def __init__(self, key):
     self.api_key = key
     self.api = Proxies(api_key=key)
예제 #37
0
 def test_get_uncle_by_blocknumber_index(self):
     api = Proxies(api_key=API_KEY)
     uncle = api.get_uncle_by_blocknumber_index(BLOCK_NUMBER, UNCLE_INDEX)
     print(uncle)
     self.assertEqual(uncle['difficulty'], hex(UNCLE_DIFFICULTY))
예제 #38
0
from os.path import isfile
from requests import HTTPError
from etherscan.proxies import Proxies

blocks_path = "../blocks_new/"
max_files_in_dir = 5000
files_in_dir = 0
current_dir = 0

sleep_time = 0.2
first_block_num = 4650000
last_block_num = 4825000

with open('api_key.json', mode='r') as key_file:
    key = loads(key_file.read())['key']
api = Proxies(api_key=key)

try:
    mkdir(blocks_path + str(current_dir))
except OSError:
    print('Failed to create directory %s' % blocks_path + str(current_dir))
else:
    print('Created directory %s successfully' % blocks_path + str(current_dir))

print("Downloading transactions for blocks: {} to {}".format(
    first_block_num, last_block_num))
for i in tqdm(range(4708444, last_block_num + 1)):
    try:
        block = api.get_block_by_number(i)
        minified_txs = []
        for tx in block['transactions']:
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
receipt = api.get_transaction_receipt(
    '0xb03d4625fd433ad05f036abdc895a1837a7d838ed39f970db69e7d832e41205d')
print(receipt)