PHP code example of raphaelcangucu / multicoin-address-validator

1. Go to this page and download the library: Download raphaelcangucu/multicoin-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 / multicoin-address-validator example snippets




use Multicoin\AddressValidator\CurrencyFactory;
use Multicoin\AddressValidator\WalletAddressValidator;

// Create validator instance
$registry = CurrencyFactory::createRegistry();
$validator = new WalletAddressValidator($registry);

// Validate Bitcoin address
$isValid = $validator->validate('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'btc');
echo $isValid ? 'Valid' : 'Invalid'; // Output: Valid

// Validate Ethereum address (enhanced - accepts any case variation)
$isValid = $validator->validate('0x742d35Cc6339C4532CE58b5D3Ea8d5A8d6F6395C', 'eth');
echo $isValid ? 'Valid' : 'Invalid'; // Output: Valid

// Works with incorrect checksums, mixed case, or oversized addresses
$isValid = $validator->validate('0x742d35CC6339c4532CE58b5d3EA8d5a8D6f6395c999', 'eth');
echo $isValid ? 'Valid' : 'Invalid'; // Output: Valid (auto-trimmed)

// Validate with network type
$isValid = $validator->validate(
    'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
    'btc',
    ['networkType' => 'testnet']
);
echo $isValid ? 'Valid' : 'Invalid'; // Output: Valid

// Basic validation
$validator->validate('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'btc');

// With network type
$validator->validate(
    'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn',
    'btc',
    ['networkType' => 'testnet']
);

// Using currency name instead of symbol
$validator->validate('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'bitcoin');

$currencies = $validator->getCurrencies();
// Returns: [['name' => 'Bitcoin', 'symbol' => 'btc'], ...]

$currency = $validator->findCurrency('btc');
// Returns: ['name' => 'Bitcoin', 'symbol' => 'btc'] or null

$isSupported = $validator->isSupported('btc'); // true
$isSupported = $validator->isSupported('unknown'); // false

use Multicoin\AddressValidator\AbstractValidator;

class CustomValidator extends AbstractValidator
{
    public function isValidAddress(string $address, array $options = []): bool
    {
        // Your custom validation logic
        return true;
    }
}

use Multicoin\AddressValidator\Currency;
use Multicoin\AddressValidator\CurrencyRegistry;

$registry = new CurrencyRegistry();
$validator = new CustomValidator();
$currency = new Currency('MyCoin', 'myc', $validator);

$registry->register($currency);

$addresses = [
    ['address' => '1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'currency' => 'btc'],
    ['address' => '0x742d35Cc6339C4532CE58b5D3Ea8d5A8d6F6395C', 'currency' => 'eth'],
];

foreach ($addresses as $item) {
    $isValid = $validator->validate($item['address'], $item['currency']);
    echo "{$item['currency']}: " . ($isValid ? 'Valid' : 'Invalid') . "\n";
}