import asyncio
import aiohttp

bscscan_api_key = '<TRUFFLEHOG_REDACTED_BSCSCAN>'

# Create a semaphore with a limit of n
semaphore = asyncio.Semaphore(5)

async def get_transactions_from_block(block_number, session):
    async with semaphore:
        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 isinstance(data['result'], str):
            print(f"Error: Cannot find the block")
            return []

        return data['result'].get('transactions', [])

async def get_newly_created_contracts(start_block, end_block):
    contract_list = []

    async def process_block(block_number, session):
        transactions = await get_transactions_from_block(block_number, session)
        return [tx for tx in transactions if 'from' in tx and tx['from'] == filter_address]

    async with aiohttp.ClientSession() as session:
        tasks = [process_block(hex(block_number), session) for block_number in range(start_block, end_block + 1)]
        results = await asyncio.gather(*tasks)

    for contracts in results:
        contract_list.extend(contracts)

    return contract_list

async def display_new_contracts(start_block, end_block):
    filter_address = '0x863b49ae97c3d2a87fd43186dfd921f42783c853'
    contracts = await get_newly_created_contracts(start_block, end_block)

    if not contracts:
        print('No new contracts found.')
    else:
        print(f'Newly created smart contracts between blocks {start_block} and {end_block}: ')
        for contract in contracts:
            print(f"Block: {contract['blockNumber']} - Address: {contract['contractAddress']}")

async def main():
    start_block = 2826940  # Replace with your desired start block
    end_block = 2826940  # Replace with your desired end block

    await display_new_contracts(start_block, end_block)

asyncio.run(main())

The code above throws an error

C:\Users\AshotxXx\PycharmProjects\UNCX\Project2\venv\Scripts\python.exe C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py 
Traceback (most recent call last):
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py", line 58, 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\UNCX\Project1\main.py", line 56, in main
    await display_new_contracts(start_block, end_block)
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py", line 43, in display_new_contracts
    contracts = await get_newly_created_contracts(start_block, end_block)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py", line 34, in get_newly_created_contracts
    results = await asyncio.gather(*tasks)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py", line 30, in process_block
    return [tx for tx in transactions if 'from' in tx and tx['from'] == filter_address]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\Project1\main.py", line 30, in <listcomp>
    return [tx for tx in transactions if 'from' in tx and tx['from'] == filter_address]
                                                                        ^^^^^^^^^^^^^^
NameError: name 'filter_address' is not defined

Process finished with exit code 1

Fix it