# Оптимизированный Возращает адреса созданных токенов в указанном интревале блоков (Обрабатывет по одному блоку)

import asyncio
import requests
import aiohttp

bscscan_api_key = '<TRUFFLEHOG_REDACTED_BSCSCAN>'

# Modify the existing functions to use async and aiohttp…

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:
            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 display_transactions(block_start, block_end):
    for block_number_int in range(block_start, block_end + 1):
        block_number = hex(block_number_int)
        transactions = await get_external_transactions(block_number)  # Add the ‘await’ keyword here

        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'])
                    print(f"New contract creation: Contract Address: {contract_address}")
            print("\n")  # Print an empty line between blocks

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

    await display_transactions(block_start, block_end)

asyncio.run(main())

Change the above code to fix the errors reflected in the answer

Traceback (most recent call last):
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject20\main.py", line 66, 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\pythonProject20\main.py", line 64, in main
    await display_transactions(block_start, block_end)
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject20\main.py", line 48, in display_transactions
    transactions = await get_external_transactions(block_number)  # Add the ‘await’ keyword here
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\pythonProject20\main.py", line 26, in get_external_transactions
    return data['result']['transactions']
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

Process finished with exit code 1