import requests
import time

API_KEY = '<TRUFFLEHOG_REDACTED_BSCSCAN>'
TOKEN_CONTRACT = '0x4401E60E39F7d3F8D5021F113306AF1759a6c168'
RPC_API_URL = 'https://bsc-dataseed.binance.org/'

def get_creation_block(api_key, contract_address):
    url = f'https://api.bscscan.com/api?module=contract&action=getsourcecode&address={contract_address}&apikey={api_key}'
    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        if result['status'] == '1' and result['result']:
            contract_details = result['result'][0]
            creation_block_str = contract_details['contract_created_at_block']
            return int(creation_block_str) if creation_block_str.isdigit() else None

    return None


def get_latest_block_number(rpc_api_url):
    data = {
    'jsonrpc': '2.0',
    'id': 1,
    'method': 'eth_blockNumber',
    'params': [],
    }
    response = requests.post(rpc_api_url, json=data)
    if response.status_code == 200:
        result = response.json()
        block_number_hex = result.get('result')
        return int(block_number_hex, 16) if block_number_hex else None

    return None


def process_blocks(api_key, contract_address, rpc_api_url):
    creation_block = get_creation_block(api_key, contract_address)
    if not creation_block:
        print('Error getting creation block')
        return

    while True:
        latest_block = get_latest_block_number(rpc_api_url)
        if latest_block is None:
            print('Error getting latest block number')
            time.sleep(10)
            continue

        for block_number in range(creation_block, latest_block + 1):
            transactions = get_transaction_list(api_key, contract_address, start_block=block_number,
                                                end_block=block_number)
            if transactions:
                hashes = [tx['hash'] for tx in transactions]
                for txn_hash in hashes:
                    print(txn_hash)

                # Use a delay to avoid exceeding the API rate limit
                time.sleep(0.5)
            else:
                print(f'Error getting transactions for block {block_number}')
         # Check for new blocks every minute
        time.sleep(60)


process_blocks(API_KEY, TOKEN_CONTRACT, RPC_API_URL)

import requests
import time

API_KEY = '<TRUFFLEHOG_REDACTED_BSCSCAN>'
TOKEN_CONTRACT = '0x4401E60E39F7d3F8D5021F113306AF1759a6c168'
RPC_API_URL = 'https://bsc-dataseed.binance.org/'

def get_creation_block(api_key, contract_address):
    url = f'https://api.bscscan.com/api?module=contract&action=getsourcecode&address={contract_address}&apikey={api_key}'
    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        if result['status'] == '1' and result['result']:
            contract_details = result['result'][0]
            creation_block_str = contract_details['contract_created_at_block']
            return int(creation_block_str) if creation_block_str.isdigit() else None

    return None


def get_latest_block_number(rpc_api_url):
    data = {
    'jsonrpc': '2.0',
    'id': 1,
    'method': 'eth_blockNumber',
    'params': [],
    }
    response = requests.post(rpc_api_url, json=data)
    if response.status_code == 200:
        result = response.json()
        block_number_hex = result.get('result')
        return int(block_number_hex, 16) if block_number_hex else None

    return None


def process_blocks(api_key, contract_address, rpc_api_url):
    creation_block = get_creation_block(api_key, contract_address)
    if not creation_block:
        print('Error getting creation block')
        return

    while True:
        latest_block = get_latest_block_number(rpc_api_url)
        if latest_block is None:
            print('Error getting latest block number')
            time.sleep(10)
            continue

        for block_number in range(creation_block, latest_block + 1):
            transactions = get_transaction_list(api_key, contract_address, start_block=block_number,
                                                end_block=block_number)
            if transactions:
                hashes = [tx['hash'] for tx in transactions]
                for txn_hash in hashes:
                    print(txn_hash)

                # Use a delay to avoid exceeding the API rate limit
                time.sleep(0.5)
            else:
                print(f'Error getting transactions for block {block_number}')
         # Check for new blocks every minute
        time.sleep(60)


process_blocks(API_KEY, TOKEN_CONTRACT, RPC_API_URL)

C:\Users\AshotxXx\PycharmProjects\UNCX\HashTokenRealTime\venv\Scripts\python.exe C:\Users\AshotxXx\PycharmProjects\UNCX\HashTokenRealTime\main.py 
Traceback (most recent call last):
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\HashTokenRealTime\main.py", line 66, in <module>
    process_blocks(API_KEY, TOKEN_CONTRACT, RPC_API_URL)
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\HashTokenRealTime\main.py", line 38, in process_blocks
    creation_block = get_creation_block(api_key, contract_address)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AshotxXx\PycharmProjects\UNCX\HashTokenRealTime\main.py", line 15, in get_creation_block
    creation_block_str = contract_details['contract_created_at_block']
                         ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'contract_created_at_block'

Process finished with exit code 1

Fix it