amashukov / bitcoin-cash-php
Bitcoin Cash SDK for PHP — CashAddr codec with token-aware CashTokens types and a typed Bitcoin Cash Node (BCHN) JSON-RPC client. Umbrella package pulling the pure-PHP Bitcoin Cash stack.
Requires
- php: >=8.3
- amashukov/bchn-rpc-client-php: ^0.1.0
- amashukov/cashaddr-php: ^0.1.0
Requires (Dev)
- amashukov/rector-php-rules: ^0.4.1
- friendsofphp/php-cs-fixer: ^3.50
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- rector/rector: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Pure-PHP Bitcoin Cash SDK — CashAddr codec with token-aware CashTokens types and a typed Bitcoin Cash Node JSON-RPC client in one composer require.
amashukov/bitcoin-cash-php is a standalone Bitcoin Cash SDK for PHP — an umbrella package that pulls the Bitcoin Cash primitives a PHP service needs to receive and send BCH through its own node: a CashAddr codec that understands the token-aware CashTokens address types, and a typed JSON-RPC client that speaks the Bitcoin Cash Node (BCHN) dialect with exact satoshi amounts. Pure PHP, no Symfony, no blockchain-library dependencies.
Features
- CashAddr — encode / decode with the BCH polymod checksum,
bitcoincash/bchtest/bchregprefixes, P2PKH, P2SH, P2SH32 and the token-awarez/rtypes as a typed enum. - BCHN JSON-RPC — wallet, UTXO, PSBT (
ALL|FORKID), raw transactions with typed prevouts,testmempoolaccept/sendrawtransactionwithallowhighfees,estimatefeein sat/byte and DSProof scores. - Exact money — satoshis as integers, CashToken amounts as decimal strings; no float anywhere on the path.
- One install — both layers through a single
composer require, each versioned in its own repository.
Why amashukov/bitcoin-cash-php
Most PHP Bitcoin libraries target Bitcoin Core and break on Bitcoin Cash in small ways: they send estimatesmartfee, a max fee rate to sendrawtransaction, an address type to getnewaddress, or they read JSON amounts as floats. This stack follows the BCHN reference signatures, understands CashTokens data and the token-aware CashAddr types, and keeps PHPStan level 9 across the surface.
Installation
composer require amashukov/bitcoin-cash-php
Usage
Each layer keeps its own namespace; import what you need:
use Amashukov\CashAddr\CashAddress; use Amashukov\CashAddr\CashAddrNetwork; use Amashukov\BchnRpc\BchnRpcClient; use Amashukov\BchnRpc\Vo\BchAmount; use Amashukov\BchnRpc\Vo\PsbtOutput; // Validate the destination, then build, sign and broadcast through the // node — see each sub-package README for the full API. $to = CashAddress::fromString($userInput, CashAddrNetwork::Mainnet); if ($to->type->isTokenAware()) { // refuse or route to a token-aware flow }
Requirements
- PHP 8.3+ on a 64-bit build
- A PSR-18 HTTP client + PSR-17 factories for the RPC client (e.g.
amashukov/http-client-php+nyholm/psr7) - A Bitcoin Cash Node with the JSON-RPC server enabled
Related packages
| Package | Layer |
|---|---|
| amashukov/cashaddr-php | CashAddr codec + typed address value object |
| amashukov/bchn-rpc-client-php | Typed BCHN JSON-RPC client over PSR-18 |
| amashukov/http-client-php | PSR-18 cURL HTTP client |
| amashukov/eth-php | Sister umbrella SDK for Ethereum / EVM |
| amashukov/ton-php | Sister umbrella SDK for TON (The Open Network) |
Quality
- PHPStan level 9 across the whole stack.
- php-cs-fixer with the
@PER-CSruleset. - GitHub Actions CI on every push.
- The CashAddr codec runs the full specification and CashTokens test vectors.
License
MIT — see LICENSE. Each bundled package is MIT-licensed in its own repository.