PHP Classes

How to Use PHP Monitoring Tools to Find Suspicious Transactions with Cryptocurrencies Using the Package Block Sense: Detect fraud in cryptocurrency transactions

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-06-25 (9 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
block-sense 1.0.0Custom (specified...5Web services, Finances, Security, PHP 8
Description 

Author

This package can detect fraud in cryptocurrency transactions.

It provides an application that can monitor cryptocurrency transactions and detect fraud by establishing rules for suspicious transactions.

The package provides a class that can send API requests to blockchain explorer services to monitor a given address.

When a transaction with that address occurs, the package checks the rules that were defined to detect if the transaction is suspicious.

The suspicious transaction can be logged for further analysis.

Innovation Award
PHP Programming Innovation award nominee
June 2025
Nominee
Vote
Fraud is a concern that many companies that implement payments on the Internet have.

One way to detect fraud is necessary to analyze the transactions to determine if they follow patterns of fraud.

This package allows implementing rules that define patterns of possible fraud in transactions with virtual currencies.

This way, payment companies can reduce the work of detection of possible fraud in this kind of transaction.

Manuel Lemos
Picture of Mohib Ullah
  Performance   Level  
Name: Mohib Ullah <contact>
Classes: 1 package by
Country: Bangladesh Bangladesh
Age: 32
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 1x

Instructions

Here’s a usage guide for the BlockSense package, covering its main features and how to get started:

BlockSense Usage Guide

1. Installation

If published on Packagist:

composer require mohib/block-sense

If using locally, add to your composer.json as a path repository (see previous instructions).

2. Autoloading

Include Composer’s autoloader in your project:

require 'vendor/autoload.php';

3. Core Components

Fraud Detection

  • FraudDetector: Central class to manage and apply fraud rules.
  • Rules: Built-in rules for fraud detection: - `HighValueRule`: Flags high-value transactions. - `SuspiciousAddressRule`: Flags transactions to/from suspicious addresses. - `UnknownSenderRule`: Flags transactions from unknown senders.

Example:

use BlockSense\FraudDetector;
use BlockSense\Rules\HighValueRule;
use BlockSense\Rules\SuspiciousAddressRule;

$detector = new FraudDetector();
$detector->addRule(new HighValueRule(1000)); // Flag tx > 1000
$detector->addRule(new SuspiciousAddressRule(['0xBAD1', '0xBAD2']));

$tx = ['value' => 1500, 'from' => '0xabc', 'to' => '0xBAD1'];
if ($detector->checkTransaction($tx)) {
    echo "Fraud detected!";
} else {
    echo "Transaction is clean.";
}

Compliance Engine

  • ComplianceEngine: For advanced compliance checks and reporting.

Block Monitoring

  • BlockMonitor: For real-time blockchain transaction monitoring.

Utilities

  • CurrencyConverter: Convert between cryptocurrencies and fiat.
  • Logger: Logging utility.

Example:

use BlockSense\Util\CurrencyConverter;

$converter = new CurrencyConverter();
$usd = $converter->convert('BTC', 'USD', 0.01);
echo \"0.01 BTC is $usd USD\";

Providers (Interfaces for Extensibility)

  • `FraudRuleInterface`: Create custom fraud rules.
  • `BlockchainProviderInterface`: Integrate with different blockchains.
  • `ExchangeRateProviderInterface`: Custom exchange rate sources.
  • `ReportGeneratorInterface`: Custom reporting.
  • `WebSocketServerInterface`: Real-time event handling.

4. Testing

To run the package’s tests:

composer install
composer test

5. Extending BlockSense

You can implement your own rules or providers by implementing the relevant interfaces in src/Providers/.

Would you like a ready-to-use README.md with this content, or more detailed code examples for any specific feature?

Example

<?php
/**
 * BlockSense Library - User Guide
 *
 * This file demonstrates how to use the BlockSense library for blockchain monitoring,
 * fraud detection, currency conversion, and compliance reporting.
 */

use BlockSense\BlockMonitor;
use
BlockSense\FraudDetector;
use
BlockSense\Util\Logger;
use
BlockSense\Util\CurrencyConverter;
use
BlockSense\ComplianceEngine;
use
BlockSense\Rules\HighValueRule;
use
BlockSense\Rules\SuspiciousAddressRule;


/**
 * ============================================================================
 * 1. BASIC SETUP AND INITIALIZATION
 * ============================================================================
 */

// Initialize the main components
$monitor = new BlockMonitor('eth', 'YOUR_API_KEY_HERE');
$detector = new FraudDetector();
$logger = new Logger();

/**
 * ============================================================================
 * 2. FRAUD DETECTION CONFIGURATION
 * ============================================================================
 */

// Transactions > 100 ETH (assuming value is in wei)
$detector->addRule(new HighValueRule(100 * 1e18));

// Known suspicious addresses
$detector->addRule(new SuspiciousAddressRule(['0x123...', '0x456...']));

// Example: Add a custom rule class for rapid transactions if available
// $detector->addRule(new RapidTransactionRule(10, 60)); // Uncomment if implemented

// Add custom fraud detection rules (must implement FraudRuleInterface)
class SelfTransferOrZeroValueRule implements \BlockSense\Providers\FraudRuleInterface {
    public function
apply(): callable {
        return function(
$transaction) {
           
// Self-transfer detection
           
if ($transaction['from'] === $transaction['to']) {
                return
true; // Flag as suspicious
           
}
           
// Zero-value transaction detection
           
if ($transaction['value'] == 0) {
                return
true; // Flag as suspicious
           
}
            return
false; // Not suspicious
       
};
    }
}
$detector->addRule(new SelfTransferOrZeroValueRule());

/**
 * ============================================================================
 * 3. ADDRESS MONITORING
 * ============================================================================
 */

// Monitor a specific address for suspicious activity
$addressToMonitor = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';

// Continuous monitoring loop
while (true) {
    try {
       
$transactions = $monitor->monitorAddress($addressToMonitor);
       
        foreach (
$transactions as $transaction) {
           
// Check if transaction is suspicious
           
if ($detector->checkTransaction($transaction)) {
               
// Log the suspicious transaction
               
Logger::logFraud($transaction);
               
               
// You can add your custom alert logic here
               
echo "Suspicious transaction detected: " . $transaction['hash'] . "\n";
            }
        }
       
       
// Wait before next check (15 seconds)
       
sleep(15);
       
    } catch (
Exception $e) {
       
Logger::logError('Monitoring error: ' . $e->getMessage());
       
sleep(30); // Wait longer on error
   
}
}

/**
 * ============================================================================
 * 4. CURRENCY CONVERSION
 * ============================================================================
 */

// Initialize currency converter with default provider
$converter = new CurrencyConverter();

// Convert crypto to fiat
try {
   
$ethAmount = 1.5;
   
$usdValue = $converter->cryptoToFiat($ethAmount, 'ETH', 'USD');
    echo
"{$ethAmount} ETH = \${$usdValue} USD\n";
} catch (
Exception $e) {
   
Logger::logError('Currency conversion error: ' . $e->getMessage());
}

// Convert fiat to crypto
try {
   
$usdAmount = 100;
   
$btcAmount = $converter->fiatToCrypto($usdAmount, 'USD', 'BTC');
    echo
"\${$usdAmount} USD = {$btcAmount} BTC\n";
} catch (
Exception $e) {
   
Logger::logError('Currency conversion error: ' . $e->getMessage());
}

/**
 * ============================================================================
 * 5. COMPLIANCE ENGINE
 * ============================================================================
 */

// Initialize compliance engine
$complianceEngine = new ComplianceEngine();

// Wait for transaction confirmations
$transactionHash = '0x1234567890abcdef...';
try {
   
$confirmations = $complianceEngine->waitForConfirmations($transactionHash, 6, 'ETH');
    echo
"Transaction confirmed with {$confirmations} confirmations\n";
} catch (
Exception $e) {
   
Logger::logError('Confirmation error: ' . $e->getMessage());
}

// Generate compliance reports
$addressForReport = '0xabc123def456...';
try {
   
// Generate FATF compliance report
   
$fatfReport = $complianceEngine->generateReport($addressForReport, ['FATF']);
    echo
"FATF Report: " . json_encode($fatfReport, JSON_PRETTY_PRINT) . "\n";
   
   
// Generate OFAC compliance report
   
$ofacReport = $complianceEngine->generateReport($addressForReport, ['OFAC']);
    echo
"OFAC Report: " . json_encode($ofacReport, JSON_PRETTY_PRINT) . "\n";
   
   
// Generate comprehensive report
   
$comprehensiveReport = $complianceEngine->generateReport($addressForReport, ['FATF', 'OFAC', 'GDPR']);
    echo
"Comprehensive Report: " . json_encode($comprehensiveReport, JSON_PRETTY_PRINT) . "\n";
   
} catch (
Exception $e) {
   
Logger::logError('Report generation error: ' . $e->getMessage());
}

/**
 * ============================================================================
 * 6. ADVANCED USAGE EXAMPLES
 * ============================================================================
 */

// Example: Monitor multiple addresses
$addressesToMonitor = [
   
'0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
   
'0x1234567890abcdef1234567890abcdef12345678',
   
'0xabcdef1234567890abcdef1234567890abcdef12'
];

foreach (
$addressesToMonitor as $address) {
   
$transactions = $monitor->monitorAddress($address);
   
// Process transactions...
}

// Example: Custom logging
Logger::logInfo('Application started');
Logger::logWarning('High transaction volume detected');
Logger::logError('API rate limit exceeded');

// Example: Batch processing
$batchSize = 100;
$transactions = $monitor->getBatchTransactions($addressToMonitor, $batchSize);

foreach (
$transactions as $transaction) {
    if (
$detector->checkTransaction($transaction)) {
       
Logger::logFraud($transaction);
    }
}

/**
 * ============================================================================
 * 7. ERROR HANDLING BEST PRACTICES
 * ============================================================================
 */

// Always wrap API calls in try-catch blocks
try {
   
$result = $monitor->monitorAddress($addressToMonitor);
} catch (
BlockSense\Exceptions\ApiException $e) {
   
Logger::logError('API Error: ' . $e->getMessage());
   
// Handle API-specific errors
} catch (BlockSense\Exceptions\RateLimitException $e) {
   
Logger::logError('Rate limit exceeded: ' . $e->getMessage());
   
sleep(60); // Wait before retrying
} catch (Exception $e) {
   
Logger::logError('Unexpected error: ' . $e->getMessage());
}

/**
 * ============================================================================
 * 8. CONFIGURATION OPTIONS
 * ============================================================================
 */

// Configure monitoring intervals
$monitor->setPollingInterval(30); // Check every 30 seconds

// Configure fraud detection sensitivity
$detector->setSensitivity(FraudDetector::SENSITIVITY_HIGH);

// Configure currency conversion cache
$converter->setCacheEnabled(true);
$converter->setCacheDuration(300); // 5 minutes

// Configure compliance engine
$complianceEngine->setMaxConfirmations(12);
$complianceEngine->setConfirmationTimeout(3600); // 1 hour

/**
 * ============================================================================
 * 9. PERFORMANCE TIPS
 * ============================================================================
 */

// Use batch processing for large datasets
// Implement proper error handling and retry logic
// Cache frequently accessed data
// Use appropriate polling intervals
// Monitor memory usage with large transaction sets

echo "BlockSense Library User Guide - All examples completed successfully!\n";


Details

BlockSense - Real-Time Blockchain Monitoring & Fraud Detection for PHP

PHP 8.2+ License: MIT Tests

 
 /$$$$$$$  /$$                     /$$        /$$$$$$                                         
| $$__  $$| $$                    | $$       /$$__  $$                                        
| $$  \ $$| $$  /$$$$$$   /$$$$$$$| $$   /$$| $$  \__/  /$$$$$$  /$$$$$$$   /$$$$$$$  /$$$$$$ 
| $$$$$$$ | $$ /$$__  $$ /$$_____/| $$  /$$/|  $$$$$$  /$$__  $$| $$__  $$ /$$_____/ /$$__  $$
| $$__  $$| $$| $$  \ $$| $$      | $$$$$$/  \____  $$| $$$$$$$$| $$  \ $$|  $$$$$$ | $$$$$$$$
| $$  \ $$| $$| $$  | $$| $$      | $$_  $$  /$$  \ $$| $$_____/| $$  | $$ \____  $$| $$_____/
| $$$$$$$/| $$|  $$$$$$/|  $$$$$$$| $$ \  $$|  $$$$$$/|  $$$$$$$| $$  | $$ /$$$$$$$/|  $$$$$$$
|_______/ |__/ \______/  \_______/|__/  \__/ \______/  \_______/|__/  |__/|_______/  \_______/
---------------------------------------------------------------
REAL-TIME BLOCKCHAIN MONITORING & FRAUD DETECTION FOR PHP
---------------------------------------------------------------

> Enterprise-grade blockchain security for PHP developers

? Features

  • Real-time monitoring (BTC/ETH/BSC) via WebSocket/API
  • Custom fraud rules (high-value TXs, unknown senders, etc.)
  • Compliance tools (FATF/OFAC report generation)
  • Laravel & Symfony integration
  • AI-powered anomaly detection

  Files folder image Files (29)  
File Role Description
Files folder image.github (2 directories)
Files folder imagesrc (3 files, 4 directories)
Files folder imagetests (6 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file Example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (29)  /  .github  
File Role Description
Files folder imageISSUE_TEMPLATE (2 files)
Files folder imageworkflows (2 files)

  Files folder image Files (29)  /  .github  /  ISSUE_TEMPLATE  
File Role Description
  Accessible without login Plain text file bug_report.md Data Auxiliary data
  Accessible without login Plain text file feature_request.md Data Auxiliary data

  Files folder image Files (29)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data
  Accessible without login Plain text file test.svg Data Auxiliary data

  Files folder image Files (29)  /  src  
File Role Description
Files folder imageException (1 file)
Files folder imageProviders (5 files)
Files folder imageRules (3 files)
Files folder imageUtil (2 files, 1 directory)
  Plain text file BlockMonitor.php Class Class source
  Plain text file ComplianceEngine.php Class Class source
  Plain text file FraudDetector.php Class Class source

  Files folder image Files (29)  /  src  /  Exception  
File Role Description
  Plain text file ComplianceException.php Class Class source

  Files folder image Files (29)  /  src  /  Providers  
File Role Description
  Plain text file BlockchainProviderInterface.php Class Class source
  Plain text file ExchangeRateProviderInterface.php Class Class source
  Plain text file FraudRuleInterface.php Class Class source
  Plain text file ReportGeneratorInterface.php Class Class source
  Plain text file WebSocketServerInterface.php Class Class source

  Files folder image Files (29)  /  src  /  Rules  
File Role Description
  Plain text file HighValueRule.php Class Class source
  Plain text file SuspiciousAddressRule.php Class Class source
  Plain text file UnknownSenderRule.php Class Class source

  Files folder image Files (29)  /  src  /  Util  
File Role Description
Files folder imageNetworking (1 file)
  Plain text file CurrencyConverter.php Class Class source
  Plain text file Logger.php Class Class source

  Files folder image Files (29)  /  src  /  Util  /  Networking  
File Role Description
  Plain text file HttpClient.php Class Class source

  Files folder image Files (29)  /  tests  
File Role Description
  Plain text file BlockMonitorTest.php Class Class source
  Plain text file CurrencyConverterTest.php Class Class source
  Plain text file FraudDetectorTest.php Class Class source
  Plain text file HighValueRuleTest.php Class Class source
  Plain text file SuspiciousAddressRuleTest.php Class Class source
  Plain text file UnknownSenderRuleTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0