# Выводит хэши всех транзакций указанного токена в реальном времени
# Нужно указать с какого блока начинается обработка
# Только для контрактов созданных на платформе UNCX

import requests
import time

API_KEY = '<TRUFFLEHOG_REDACTED_BSCSCAN>'
TARGET_ADDRESS = '0xd69e826715EEf32b243eC240E7b90861d89529fe'
START_BLOCK = 28949445
RPC_API_URL = 'https://bsc-dataseed.binance.org/'

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 get_transactions_from_block(api_key, target_address, start_block, end_block):
    url = f'https://api.bscscan.com/api?module=account&action=tokentx&contractaddress={target_address}&startblock={start_block}&endblock={end_block}&sort=asc&apikey={api_key}'
    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        return result['result'] if result['status'] == '1' else None

def process_blocks(start_block, target_address, api_key, rpc_api_url):
    last_processed_block = start_block

    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(last_processed_block, latest_block + 1):
            print(f'Processing block {block_number}')
            transactions = get_transactions_from_block(api_key, target_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 overloading the server
            time.sleep(1)

        last_processed_block = latest_block + 1

        # Check for new blocks every minute
        time.sleep(5)

process_blocks(START_BLOCK, TARGET_ADDRESS, API_KEY, RPC_API_URL)


The code above returns a hash located in block 28949450 there is a transaction with method id "0xf305d719": "Add Liquidity ETH"

The code below does not return a hash and method id, although there is a transaction in block 28949450 with method id "0xf305d719": "Add Liquidity ETH"
I remind you that the transactions are on the page https://bscscan.com/token/0xd69e826715eef32b243ec240e7b90861d89529fe
Print me a transaction with hash 0x5ccf26c5e277c8177d9b743ab62011240029746d14aa6cb802e265234deb3e7d
Block number

import requests
import time

API_KEY = '<TRUFFLEHOG_REDACTED_BSCSCAN>'
TARGET_ADDRESS = '0xd69e826715EEf32b243eC240E7b90861d89529fe'
START_BLOCK = 28949445
RPC_API_URL = 'https://bsc-dataseed.binance.org/'

method_ids = {
    "0xe8e33700": "Add Liquidity",
    "0xf305d719": "Add Liquidity ETH",
    "0xeaaed442": "Add Liquidity BNB",
    "0x4bb278f3": "finalize",
    "0x8a8c523c": "Enable Trading",
    "0xc9567bf9": "Open Trading",
    "0x07279357": "Lock",
    "0x6167aa61": "Lock Tokens",
    "0x8af416f6": "Lock LP Token",
    "0x715018a6": "renounceOwnership",
    "0xa57e3141": "Renounce Lock Ownership",
}

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 get_transactions_from_block(api_key, target_address, start_block, end_block):
    url = f'https://api.bscscan.com/api?module=account&action=tokentx&contractaddress={target_address}&startblock={start_block}&endblock={end_block}&sort=asc&apikey={api_key}'
    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        return result['result'] if result['status'] == '1' else None

def get_transactions_from_block(api_key, target_address, start_block, end_block):
    url = f'https://api.bscscan.com/api?module=account&action=tokentx&contractaddress={target_address}&startblock={start_block}&endblock={end_block}&sort=asc&apikey={api_key}'
    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        return result['result'] if result['status'] == '1' else None

def process_blocks(start_block, target_address, api_key, rpc_api_url):
    last_processed_block = start_block

    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(last_processed_block, latest_block + 1):
            print(f'Processing block {block_number}')
            transactions = get_transactions_from_block(api_key, target_address, start_block=block_number, end_block=block_number)
            if transactions:
                method_ids_found = [(tx['hash'], tx['input'][:10]) for tx in transactions]
                for txn_hash, method_id in method_ids_found:
                    method_name = method_ids.get(method_id)
                    if method_name:
                        print(f"{txn_hash}: {method_name}")

            last_processed_block = block_number + 1

            # Use a delay to avoid overloading the server
            time.sleep(1)

        # Check for new blocks every minute
        time.sleep(5)

process_blocks(START_BLOCK, TARGET_ADDRESS, API_KEY, RPC_API_URL)


28949450 and method id "0xf305d719": "Add Liquidity ETH"