# Возращает адреса созданных токенов в указанном интревале блоков!!!

import asyncio
import requests
import aiohttp

bscscan_api_key = '<TRUFFLEHOG_REDACTED_BSCSCAN>'

async def get_external_transactions(block_number):
    async with aiohttp.ClientSession() as session:
        url = f'https://api.bscscan.com/api?module=proxy&action=eth_getBlockByNumber&tag={block_number}&boolean=true&apikey={bscscan_api_key}'

        try:
            async with session.get(url) as response:
                data = await response.json()
        except Exception as e:
            print(f'Error in API request: {e}')
            return []

        if data['result'] is None or not isinstance(data['result'], dict):
            print(f"Error: Cannot find the block")
            return []

        return data['result']['transactions']


async def get_contract_address(tx_hash):
    async with aiohttp.ClientSession() as session:
        url = f'https://api.bscscan.com/api?module=proxy&action=eth_getTransactionReceipt&txhash={tx_hash}&apikey={bscscan_api_key}'

        try:
            async with session.get(url) as response:
                data = await response.json()
        except Exception as e:
            print(f'Error in API request: {e}')
            return None

        if data['result'] is None:
            return None

        return data['result']['contractAddress']

async def get_contract_name(contract_address):
    async with aiohttp.ClientSession() as session:
        method_signature = '0x06fdde03'
        url = f'https://api.bscscan.com/api?module=proxy&action=eth_call&to={contract_address}&data={method_signature}&tag=latest&apikey={bscscan_api_key}'

        try:
            async with session.get(url) as response:
                data = await response.json()
        except Exception as e:
            print(f'Error in API request: {e}')
            return None

        if not data.get('result') or data['result'][:2] == '0x':
            return None

        return bytes.fromhex(data['result'][2:]).decode('utf-8')

async def display_transactions(block_start, block_end):
    async def process_block(block_number_int):
        block_number = hex(block_number_int)
        transactions = await get_external_transactions(block_number)

        if not transactions:
            print(f'No transactions found in block {block_number_int}')
        else:
            print(f'Transactions in block {block_number_int}:')
            for tx in transactions:
                if tx['to'] is None:
                    contract_address = await get_contract_address(tx['hash'])
                    contract_name = await get_contract_name(contract_address)
                    print(f'New contract creation: Contract Address: {contract_address} - Contract Name: {contract_name}')
            print("\n")  # Print an empty line between blocks


    tasks = [process_block(block_number) for block_number in range(block_start, block_end + 1)]
    await asyncio.gather(*tasks)

async def main():
    block_start = 28524001  # Replace with your desired starting block number
    block_end = 28525888  # Replace with your desired ending block number

    await display_transactions(block_start, block_end)

asyncio.run(main())


Above is the code. The answer is below

No transactions found in block 28525700
Error: Cannot find the block
No transactions found in block 28525360
Error: Cannot find the block
No transactions found in block 28525244
Transactions in block 28524587:


Error: Cannot find the block
No transactions found in block 28525206
Error: Cannot find the block
No transactions found in block 28525111
Transactions in block 28524688:


Error: Cannot find the block
No transactions found in block 28525413
Error: Cannot find the block
No transactions found in block 28525191
Error: Cannot find the block
No transactions found in block 28525312
Transactions in block 28524657:


Error: Cannot find the block
No transactions found in block 28525806
Error: Cannot find the block
No transactions found in block 28525734
Transactions in block 28524782:


Error: Cannot find the block
No transactions found in block 28525710
Transactions in block 28524810:


Traceback (most recent call last):
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject21\main.py", line 86, in <module>
    asyncio.run(main())
  File "C:\Users\AshotxXx\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject21\main.py", line 84, in main
    await display_transactions(block_start, block_end)
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject21\main.py", line 78, in display_transactions
    await asyncio.gather(*tasks)
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject21\main.py", line 71, in process_block
    contract_address = await get_contract_address(tx['hash'])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject21\main.py", line 41, in get_contract_address
    return data['result']['contractAddress']
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

Process finished with exit code 1


write code to fix these errors