Converts old Bitcoin Cash addresses to the new CashAddr format and vice versa in a Laravel friendly package. Based off Har01d's CashAddressPHP code.
Begin by pulling in the package through Composer.
composer require submtd/cashaddr-converter
Next, if you are using Laravel 5.4, you will need to include the service provider and optionally, the alias in your config/app.php
file. If you are using Laravel 5.5, these will be discovered automatically.
'providers' => [
Submtd\CashaddrConverter\Providers\CashaddrConverterServiceProvider::class,
];
'aliases' => [
'CashaddrConverter' => Submtd\CashaddrConverter\Facades\CashaddrConverterFacade::class,
];
A facade and a helper function are provided to make it super simple to use.
// convert from a legacy address to a cashaddr address
$legacyAddress = '1PchCm7XXAjifhpchPB8wR2WG5rzMFqjnR';
CashaddrConverter::convertToCashaddr($legacyAddress);
// returns bitcoincash:qrup9c40gr9usrz6m7rg7rknjmsp685r2yhxkdx8tf
// convert from a cashaddr address to a legacy address
$cashaddrAddress = 'bitcoincash:qrup9c40gr9usrz6m7rg7rknjmsp685r2yhxkdx8tf';
CashaddrConverter::convertFromCashaddr($cashaddrAddress);
// returns 1PchCm7XXAjifhpchPB8wR2WG5rzMFqjnR
// convert from a legacy address to a cashaddr address
$legacyAddress = '1PchCm7XXAjifhpchPB8wR2WG5rzMFqjnR';
convertToCashaddr($legacyAddress);
// returns bitcoincash:qrup9c40gr9usrz6m7rg7rknjmsp685r2yhxkdx8tf
// convert from a cashaddr address to a legacy address
$cashaddrAddress = 'bitcoincash:qrup9c40gr9usrz6m7rg7rknjmsp685r2yhxkdx8tf';
convertFromCashaddr($cashaddrAddress);
// returns 1PchCm7XXAjifhpchPB8wR2WG5rzMFqjnR
If this project helped you save some development time, feel free to buy me a beer ;)