Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andkom/php-bitcoin-address
A simple P2PK, P2PKH, P2SH, P2WPKH, P2WSH, P2TR output script/address parser/generator/validator.
https://github.com/andkom/php-bitcoin-address
address address-parser address-validation bitcoin bitcoin-address bitcoin-script output schnorr schnorr-signatures script taproot
Last synced: about 6 hours ago
JSON representation
A simple P2PK, P2PKH, P2SH, P2WPKH, P2WSH, P2TR output script/address parser/generator/validator.
- Host: GitHub
- URL: https://github.com/andkom/php-bitcoin-address
- Owner: andkom
- License: mit
- Created: 2018-12-17T17:51:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-16T20:22:13.000Z (12 months ago)
- Last Synced: 2024-09-19T00:47:23.001Z (about 2 months ago)
- Topics: address, address-parser, address-validation, bitcoin, bitcoin-address, bitcoin-script, output, schnorr, schnorr-signatures, script, taproot
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 19
- Watchers: 3
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## PHP Bitcoin Address
A simple P2PK, P2PKH, P2SH, P2WPKH, P2WSH, P2TR output script/address parser/generator/validator.
**Supported types:**
- Pay-To-PubKey (P2PK)
- Pay-To-PubKeyHash (P2PKH)
- Pay-To-Multisig (P2MS)
- Pay-To-ScriptHash (P2SH)
- Pay-To-WitnessPubKeyHash (P2WPKH)
- Pay-To-WitnessScriptHash (P2WSH)
- Pay-To-Taproot (P2TR)
- P2WPKH-over-P2SH
- P2WSH-over-P2SH
- any combination**Supported networks:**
- Bitcoin
- Bitcoin Testnet
- Bitcoin Gold
- Bitcoin Cash
- Litecoin
- Litecoin Testnet
- Dogecoin
- Dogecoin Testnet
- Viacoin
- Viacoin Testnet
- Dash
- Dash Testnet
- Zcash### Installation
```bash
composer require andkom/php-bitcoin-address
```### Examples
Generate a P2PK/P2PKH address:
```php
$address = OutputFactory::p2pk($pubKey)->address();
$address = OutputFactory::p2pkh($pubKeyHash)->address();
```Generate a P2MS address:
```php
$address = OutputFactory::p2ms(2, [$pubKey1, $pubKey2, $pubKey3])->address();
```Generate a P2SH address:
```php
$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$address = $factory->p2sh($p2ms)->address();
```Generate a P2WPKH address:
```php
$address = OutputFactory::p2wpkh($pubKeyHash)->address();
```Generate a P2WSH address:
```php
$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$address = $factory->p2wsh($p2ms)->address();
```Generate a P2WPKH-over-P2SH address:
```php
$factory = new OutputFactory();
$p2wpkh = $factory->p2wpkh($pubKeyHash);
$address = $factory->p2sh($p2wpkh)->address();
```Generate a P2WSH-over-P2SH address:
```php
$factory = new OutputFactory();
$p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]);
$p2wsh = $factory->p2wsh($p2ms);
$address = $factory->p2sh($p2wsh)->address();
```Generate a P2TR address:
```php
$taprootPubKey = Taproot::construct($pubKey);
$address = OutputFactory::p2tr($taprootPubKey)->address();
```Generate an address from an output script:
```php
$address = OutputFactory::fromScript($script)->address();
```Decode a Bitcoin address:
```php
$output = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
```Get a Bitcoin address type:
```php
$type = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')->type(); // p2pkh
```Validate a Bitcoin address:
```php
NetworkFactory::bitcoin()->validateAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'); // true
```