PHP code example of barechain / bitcoin-address

1. Go to this page and download the library: Download barechain/bitcoin-address 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/ */

    

barechain / bitcoin-address example snippets


$address = OutputFactory::p2pk($pubKey)->address(); 
$address = OutputFactory::p2pkh($pubKeyHash)->address(); 

$address = OutputFactory::p2ms(2, [$pubKey1, $pubKey2, $pubKey3])->address();

$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$address = $factory->p2sh($p2ms)->address();

$address = OutputFactory::p2wpkh($pubKeyHash)->address();

$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$address = $factory->p2wsh($p2ms)->address();

$factory = new OutputFactory();
$p2wpkh = $factory->p2wpkh($pubKeyHash);
$address = $factory->p2sh($p2wpkh)->address();

$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$p2wsh = $factory->p2wsh($p2ms);
$address = $factory->p2sh($p2wsh)->address();

$address = OutputFactory::fromScript($script)->address();