<?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.';
}
}
// Get the underlying multicoin validator instance
$validator = CryptoAddressValidator::getValidator();
// Use advanced features directly
$result = $validator->validateWithDetails($address, $currency);