PHPackages                             ekliptor/cashp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. ekliptor/cashp

ActiveLibrary[Payment Processing](/categories/payments)

ekliptor/cashp
==============

PHP library for Bitcoin Cash (BCH) and SLP token payments

1.2.12(5y ago)121558[2 issues](https://github.com/Ekliptor/cashp/issues)[5 PRs](https://github.com/Ekliptor/cashp/pulls)MITPHP

Since Jun 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Ekliptor/cashp)[ Packagist](https://packagist.org/packages/ekliptor/cashp)[ RSS](/packages/ekliptor-cashp/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (2)Versions (30)Used By (0)

CashP - PHP library for Bitcoin Cash (BCH) and SLP token payments
=================================================================

[](#cashp---php-library-for-bitcoin-cash-bch-and-slp-token-payments)

This is a PHP library to enable [BitCoin Cash (BCH)](https://www.bitcoincash.org/) and [SLP token](https://simpleledger.cash/) payments. You can easily use this with WordPress, Laravel and other PHP frameworks.

#### Installation

[](#installation)

With composer (recommended):

```
composer require "ekliptor/cashp"

```

Manual installation:

1. Download the source code and include `cashp.php` from the root directory of this library.
2. Download the source of this [PHP QR-code package](https://github.com/Ekliptor/qr-code) and extract it to `src/phpqrcode`

#### Requirements

[](#requirements)

```
PHP >= 7.1

```

Features
--------

[](#features)

- on-chain payments without going through a 3rd party
- configurable open-source API backends such as: [rest.bitcoin.com](https://github.com/Bitcoin-com/rest.bitcoin.com) or [BCHD](https://github.com/gcash/bchd)
- 1-time address generation for payments using xPub (so your wallet's private key is not stored on the server)
- generate QR codes with BCH and SLP payment URIs

Docs
----

[](#docs)

Take a look at [code examples](https://github.com/Ekliptor/cashp/tree/master/examples).

#### CashP class

[](#cashp-class)

##### \_\_construct(CashpOptions $options = null)

[](#__constructcashpoptions-options--null)

Create the main API class.

- `CashpOptions $options` - (optional) API options (see below)

##### getRate(): ExchangeRate

[](#getrate-exchangerate)

Return the exchange rate API.

##### getBlockchain(): AbstractBlockchainApi

[](#getblockchain-abstractblockchainapi)

Return the Blockchain API to generate addresses, check balances, transactions,...

##### generateQrCodeForAddress(string $fileLocal, string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = ""): bool

[](#generateqrcodeforaddressstring-filelocal-string-address-float-amountbch-float-amounttoken--00-string-tokenid---bool)

Generate a QR code for a payment.

- `string $fileLocal` - A path on your local filesystem to store the QR code file. This should be accessible from the web if you want to display the QR code to users. If the given file already exists it will NOT be overwritten (QR codes are meant to be generated &amp; cached in your web temp directory).
- `string $address` - The (1-time) BCH (or SLP) address created for this payment.
- `float $amountBCH` - The amount in BCH. Can be 0 if the user pays the full amount in SLP tokens.
- `float $amountToken` - (optional) The amount of the optional token to be received.
- `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken &gt; 0.

returns `bool` - true on success, false otherwise

---

##### createPaymentURI(string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = ""): string

[](#createpaymenturistring-address-float-amountbch-float-amounttoken--00-string-tokenid---string)

Return a payment URI (starting with "bitcoincash:" or "simpleledger:" if $amountToken &gt; 0) for the given $address.

- `string $address` - The receiving BCH (or SLP) address.
- `float $amountBCH` - The amount in BCH to receive.
- `float $amountToken` - (optional) The amount of SLP tokens to receive.
- `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken &gt; 0.

returns `string`

---

##### getBadgerButton(array $btnConf, string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = ""): string

[](#getbadgerbuttonarray-btnconf-string-address-float-amountbch-float-amounttoken--00-string-tokenid---string)

Get the HTML code of a BadgerButton. See

- `array $btnConf` - associative array with buttom config
    - text (string) The text of the button
    - callback (string, optional) The name of a callback function present on the global window to be called after payment. Parameters: string chainTxID
    - cssClass (string, optional) Additional CSS classes for the button.
    - forceIndludeJs (bool, optional) default false - Include the JavaScript library again. Only use this if you are generating HTML for multiple pages.
- `string $address` - The receiving BCH (or SLP) address.
- `float $amountBCH` - The amount in BCH to receive.
- `float $amountToken` - (optional) The amount of SLP tokens to receive.
- `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken &gt; 0.

returns `string` - The button HTML.

---

##### isValidBchAddress(string $bchAddress): bool

[](#isvalidbchaddressstring-bchaddress-bool)

Check if a BCH address is valid.

- `string $bchAddress` - The address in CashAddress format starting with 'bitcoincash:'

returns `bool` - True if the address is valid, false otherwise.

---

##### isValidSlpAddress(string $slpAddress): bool

[](#isvalidslpaddressstring-slpaddress-bool)

Check if a SLP address is valid.

- `string $slpAddress` - The address starting with 'simpleledger:'

returns `bool` - True if the address is valid, false otherwise.

---

##### getReturnAddress(Transaction $tx): string

[](#getreturnaddresstransaction-tx-string)

Gets the return BCH address (belonging to the sender senders address) defined as the last address in transaction outputs.

- `Transaction $tx` - The transaction from getTransaction() call.

returns `string` - the address

---

##### getReturnSlpAddress(Transaction $tx): string

[](#getreturnslpaddresstransaction-tx-string)

Gets the return SLP address (belonging to the sender senders address) defined as the last address in transaction outputs.

- `Transaction $tx` - The transaction from getTransaction() call.

returns `string` - the address

---

#### CashpOptions class

[](#cashpoptions-class)

A set of advanced config properties.

- `$httpAgent = null` - The HTTP implementation used to make HTTP requests. Values: BasicHttpAgent|CurlHttpAgent|WordpressHttpAgent Defaults to BasicHttpAgent, but you should use a better one according to your PHP setup.
- `$exchangeRateExpirationMin = 60` - How long the crawled exchange rate shall stay in cache. Currently rates are not saved beyond script execution.
- `$httpTimeoutSec = 10` - The timeout for HTTP requests to the REST API backend.
- `$blockchainApiImplementation = "BitcoinComRestApi"` - The REST API backend implementation to use. Allowed values: BitcoinComRestApi|BchdProtoGatewayApi|SlpDbApi

#### ExchangeRate class

[](#exchangerate-class)

An API to get BCH exchanges rates to fiat currencies.

##### getRate(string $currency = "USD"): float

[](#getratestring-currency--usd-float)

Get the current exchange rate for BCH.

- `string $currency` - A fiat currency such as USD|EUR|JPY

returns `float`

---

#### BlockchainApi class

[](#blockchainapi-class)

The Blockchain API to generate addresses, check balances, transactions,...

##### static setLogger(callable $loggerFn): void

[](#static-setloggercallable-loggerfn-void)

Set a logger function for errors and debug output. Use this to write to a logfile or database. If no function is provided everything will be printed using 'echo'.

- `callable $loggerFn(string $subject, mixed $error, mixed $data = null)` - parameters of the PHP callable

##### setHttpAgent(AbstractHttpAgent $agent): void

[](#sethttpagentabstracthttpagent-agent-void)

Set a a HTTP implementation for requests (cURL, Wordpress HTTP API,...)

- `AbstractHttpAgent $agent` -

##### getConfirmationCount(string $transactionID): int

[](#getconfirmationcountstring-transactionid-int)

Return the number of confirmation for the given blockchain transaction ID.

- `string $transactionID` -

returns `int` - The number of confirmations or -1 if the $transactionID doesn't exist.

---

##### createNewAddress(string $xPub, int $addressCount, string $hdPathFormat = '0/%d'): ?BchAddress

[](#createnewaddressstring-xpub-int-addresscount-string-hdpathformat--0d-bchaddress)

Creates a new address from the xPub.

- `string $xPub` - The extended public key. Called 'Master Public Key' in Electron Cash.
- `int $addressCount` - The number of the next address to generate a unique address. Usually this should be an incrementing integer.
- `string $hdPathFormat` - (optional) The HD path to be used for creating address children.

returns `BchAddress` - the address or `null` on failure

---

##### getTokenInfo(string $tokenID): ?SlpToken

[](#gettokeninfostring-tokenid-slptoken)

Get general (network-wide) info about a SLP token.

- `string $tokenID` -

returns `SlpToken` - The token or `null` on failure

---

##### getAddressBalance(string $address): float

[](#getaddressbalancestring-address-float)

Return the BCH balance of the given address (including unconfirmed transactions).

- `string $address` - The BCH address in CashAddress format.

returns `float` - The balance or -1 if the address doesn't exist.

---

##### getAddressTokenBalance(string $address, string $tokenID): float

[](#getaddresstokenbalancestring-address-string-tokenid-float)

Return the token balance of the given SLP address (including unconfirmed transactions).

- `string $address` -
- `string $tokenID` -

returns `float` - The balance or -1 if the address doesn't exist.

---

##### getAddressDetails(string $address): ?BchAddress

[](#getaddressdetailsstring-address-bchaddress)

Return the BCH Address with all its properties such as balance, TXIDs,...

- `string $address` - The BCH address in CashAddress format.

returns `BchAddress` - the address or `null` on failure

---

##### getSlpAddressDetails(string $address, string $tokenID): ?SlpTokenAddress

[](#getslpaddressdetailsstring-address-string-tokenid-slptokenaddress)

Return the SLP token details of a given address include balance, TXIDs,...

- `string $address` -
- `string $tokenID` -

returns `SlpTokenAddress` - The token or `null` on failure

---

##### getTransaction(string $transactionID): ?Transaction

[](#gettransactionstring-transactionid-transaction)

Returns a transaction with all inputs and outputs including SLP data.

- `string $transactionID` -

returns `Transaction` - The transaction or `null` on failure

---

Testing
-------

[](#testing)

To run unit tests type the following command in the project root directory (requires PHPUnit, installed automatically with Composer):

`./vendor/bin/phpunit --bootstrap vendor/autoload.php tests`

ToDo
----

[](#todo)

- add SLP address verification
- implement more functions of the REST API
- implement address creation using xPub with SLPDB (after it's supported)

Contact
-------

[](#contact)

[Twitter](https://twitter.com/ekliptor)

[WordPress plugin](https://cashtippr.com/)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

24

Last Release

1942d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/157d7fe76f0f3a101ea4bfdb4ebc4841955d6836d22f277ee1e496559ae537b6?d=identicon)[Ekliptor](/maintainers/Ekliptor)

---

Top Contributors

[![Ekliptor](https://avatars.githubusercontent.com/u/14872773?v=4)](https://github.com/Ekliptor "Ekliptor (1 commits)")

---

Tags

bitcoinbitcoin-cashcryptocurrencyecommercelaravelphpphp-libraryphp7wordpressbillingpaymentecommercebitcoincryptocurrency

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ekliptor-cashp/health.svg)

```
[![Health](https://phpackages.com/badges/ekliptor-cashp/health.svg)](https://phpackages.com/packages/ekliptor-cashp)
```

###  Alternatives

[authorizenet/authorizenet

Official PHP SDK for Authorize.Net

4729.6M46](/packages/authorizenet-authorizenet)[coingate/coingate-php

CoinGate library for PHP

56459.2k1](/packages/coingate-coingate-php)[cybersource/rest-client-php

Client SDK for CyberSource REST APIs

39881.3k6](/packages/cybersource-rest-client-php)[sumup/sumup-ecom-php-sdk

SumUp PHP SDK

51277.1k1](/packages/sumup-sumup-ecom-php-sdk)[bitpay/sdk

Complete version of the PHP library for the new cryptographically secure BitPay API

42337.5k4](/packages/bitpay-sdk)[opennode/opennode-php

OpenNode PHP library for API v1

1625.3k](/packages/opennode-opennode-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
