|
| 1 | +## PHP Bitcoin Address |
| 2 | + |
| 3 | +A simple P2PK, P2PKH, P2SH, P2WPKH, P2WSH output script/address generator. |
| 4 | + |
| 5 | +**Supported types:** |
| 6 | + |
| 7 | +- Pay-To-PubKey (P2PK) |
| 8 | +- Pay-To-PubKeyHash (P2PKH) |
| 9 | +- Pay-To-Multisig (P2MS) |
| 10 | +- Pay-To-ScriptHash (P2SH) |
| 11 | +- Pay-To-WitnessPubKeyHash (P2WPKH) |
| 12 | +- Pay-To-WitnessScriptHash (P2WSH) |
| 13 | +- P2WPKH-over-P2SH |
| 14 | +- P2WSH-over-P2SH |
| 15 | +- any combination |
| 16 | + |
| 17 | +**Supported networks:** |
| 18 | + |
| 19 | +- Bitcoin |
| 20 | +- Bitcoin Testnet |
| 21 | +- Bitcoin Regtest |
| 22 | + |
| 23 | +### Installation |
| 24 | + |
| 25 | +```bash |
| 26 | +composer require andkom/php-bitcoin-address |
| 27 | +``` |
| 28 | + |
| 29 | +### Examples |
| 30 | + |
| 31 | +Generate a P2PK/P2PKH address: |
| 32 | + |
| 33 | +```php |
| 34 | +$address = OutputFactory::p2pk($pubKey)->address(); |
| 35 | +$address = OutputFactory::p2pkh($pubKeyHash)->address(); |
| 36 | +``` |
| 37 | + |
| 38 | +Generate a P2MS address: |
| 39 | + |
| 40 | +```php |
| 41 | +$address = OutputFactory::p2ms(2, [$pubKey1, $pubKey2, $pubKey3])->address(); |
| 42 | +``` |
| 43 | + |
| 44 | +Generate a P2SH address: |
| 45 | + |
| 46 | +```php |
| 47 | +$factory = new OutputFactory(); |
| 48 | +$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); |
| 49 | +$address = $factory->p2sh($p2ms)->address(); |
| 50 | +``` |
| 51 | + |
| 52 | +Generate a P2WPKH address: |
| 53 | + |
| 54 | +```php |
| 55 | +$address = OutputFactory::p2wpkh($pubKeyHash)->address(); |
| 56 | +``` |
| 57 | + |
| 58 | +Generate a P2WSH address: |
| 59 | + |
| 60 | +```php |
| 61 | +$factory = new OutputFactory(); |
| 62 | +$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); |
| 63 | +$address = $factory->p2wsh($p2ms)->address(); |
| 64 | +``` |
| 65 | + |
| 66 | +Generate a P2WPKH-over-P2SH address: |
| 67 | + |
| 68 | +```php |
| 69 | +$factory = new OutputFactory(); |
| 70 | +$p2wpkh = $factory->p2wpkh($pubKeyHash); |
| 71 | +$address = $factory->p2sh($p2wpkh)->address(); |
| 72 | +``` |
| 73 | + |
| 74 | +Generate a P2WSH-over-P2SH address: |
| 75 | + |
| 76 | +```php |
| 77 | +$factory = new OutputFactory(); |
| 78 | +$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); |
| 79 | +$p2wsh = $factory->p2wsh($p2ms); |
| 80 | +$address = $factory->p2sh($p2wsh)->address(); |
| 81 | +``` |
0 commit comments