PHP code example of andkom / php-bitcoin-address
1. Go to this page and download the library: Download andkom/php-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/ */
andkom / php-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();
$taprootPubKey = Taproot::construct($pubKey);
$address = OutputFactory::p2tr($taprootPubKey)->address();
$address = OutputFactory::fromScript($script)->address();
$output = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
$type = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')->type(); // p2pkh
NetworkFactory::bitcoin()->validateAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'); // true
bash
composer