PHP code example of raphaelcangucu / laravel-crypto-address-validator

1. Go to this page and download the library: Download raphaelcangucu/laravel-crypto-address-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raphaelcangucu / laravel-crypto-address-validator example snippets




// config for CryptoAddressValidator
return [
    /*
    |--------------------------------------------------------------------------
    | Default Currency
    |--------------------------------------------------------------------------
    |
    | The default currency to use when validating addresses if no currency
    | is specified. This can be either a currency symbol (e.g., 'btc') or
    | the full currency name (e.g., 'bitcoin').
    |
    */
    'default_currency' => 'btc',

    /*
    |--------------------------------------------------------------------------
    | Default Network Type
    |--------------------------------------------------------------------------
    |
    | The default network type to use for validation. Options 

use CryptoAddressValidator\Facades\CryptoAddressValidator;

// Validate a Bitcoin address
$isValid = CryptoAddressValidator::validate('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'btc');
// Returns: true

// Validate an Ethereum address
$isValid = CryptoAddressValidator::validate('0x742d35Cc6339C4532CE58b5D3Ea8d5A8d6F6395C', 'eth');
// Returns: true

// Validate with options
$isValid = CryptoAddressValidator::validate(
    'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
    'btc',
    ['networkType' => 'testnet']
);
// Returns: true

// Get all supported currencies
$currencies = CryptoAddressValidator::getCurrencies();

// Find a specific currency
$currency = CryptoAddressValidator::findCurrency('btc');
// Returns: ['symbol' => 'btc', 'name' => 'Bitcoin', ...]

// Check if a currency is supported
$isSupported = CryptoAddressValidator::isSupported('btc');
// Returns: true

use CryptoAddressValidator\CryptoAddressValidator;

class PaymentController extends Controller
{
    public function validateAddress(CryptoAddressValidator $validator, Request $request)
    {
        $address = $request->input('address');
        $currency = $request->input('currency');
        
        if ($validator->validate($address, $currency)) {
            return response()->json(['valid' => true]);
        }
        
        return response()->json(['valid' => false, 'message' => 'Invalid address']);
    }
}

use CryptoAddressValidator\Facades\CryptoAddressValidator;
use Illuminate\Foundation\Http\FormRequest;

class PaymentRequest extends FormRequest
{
    public function rules()
    {
        return [
            'address' => [
                'rency address.');
                    }
                },
            ],
            'currency' => '

use CryptoAddressValidator\Facades\CryptoAddressValidator;
use Illuminate\Contracts\Validation\Rule;

class CryptoAddress implements Rule
{
    protected $currency;
    protected $options;

    public function __construct($currency, $options = [])
    {
        $this->currency = $currency;
        $this->options = $options;
    }

    public function passes($attribute, $value)
    {
        return CryptoAddressValidator::validate($value, $this->currency, $this->options);
    }

    public function message()
    {
        return 'The :attribute must be a valid ' . strtoupper($this->currency) . ' address.';
    }
}

$request->validate([
    'btc_address' => ['oAddress('eth')],
    'testnet_address' => ['

// Validate with specific network
CryptoAddressValidator::validate($address, 'btc', [
    'networkType' => 'testnet' // 'prod', 'testnet', 'stagenet'
]);

// Ethereum with strict checksum validation
CryptoAddressValidator::validate($address, 'eth', [
    'validateChecksum' => true
]);

// Custom validation options
CryptoAddressValidator::validate($address, 'xrp', [
    'validateTag' => true
]);

// Get all supported currencies
$currencies = CryptoAddressValidator::getCurrencies();
/*
Returns array like:
[
    [
        'symbol' => 'btc',
        'name' => 'Bitcoin',
        'networkTypes' => ['prod', 'testnet']
    ],
    // ... more currencies
]
*/

// Find specific currency
$bitcoin = CryptoAddressValidator::findCurrency('bitcoin');
$ethereum = CryptoAddressValidator::findCurrency('eth');

// Check support
$isSupported = CryptoAddressValidator::isSupported('btc'); // true
$isSupported = CryptoAddressValidator::isSupported('unknown'); // false

// Get the underlying multicoin validator instance
$validator = CryptoAddressValidator::getValidator();

// Use advanced features directly
$result = $validator->validateWithDetails($address, $currency);

try {
    $isValid = CryptoAddressValidator::validate($address, $currency);
} catch (\Exception $e) {
    // Handle validation errors
    Log::error('Address validation failed: ' . $e->getMessage());
    $isValid = false;
}
bash
php artisan vendor:publish --tag="crypto-address-validator-config"