PHPackages                             cbix/chain-php - 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. [API Development](/categories/api)
4. /
5. cbix/chain-php

ActiveLibrary[API Development](/categories/api)

cbix/chain-php
==============

PHP library for the Chain Bitcoin API

61.0k4[1 issues](https://github.com/Digital-Currency-Research/Chain-PHP/issues)PHP

Since Oct 6Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Digital-Currency-Research/Chain-PHP)[ Packagist](https://packagist.org/packages/cbix/chain-php)[ RSS](/packages/cbix-chain-php/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Chain-PHP
=========

[](#chain-php)

[![Build Status](https://camo.githubusercontent.com/e2b423291e495ab162b497d9b04066713c27005ddfb2f16ed80011cabeaa93d2/68747470733a2f2f7472617669732d63692e6f72672f4469676974616c2d43757272656e63792d52657365617263682f436861696e2d5048502e737667)](https://travis-ci.org/Digital-Currency-Research/Chain-PHP)[![Code Climate](https://camo.githubusercontent.com/0734bfd0b60d304ac01b556125f6766ddcb357479878ac3bbda1cf0681910105/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4469676974616c2d43757272656e63792d52657365617263682f436861696e2d5048502f6261646765732f6770612e737667)](https://codeclimate.com/github/Digital-Currency-Research/Chain-PHP)[![Test Coverage](https://camo.githubusercontent.com/e8bd5d8d81920e5d4fe22d00051775be84954c4dffd4020b086cfa4d99399b17/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4469676974616c2d43757272656e63792d52657365617263682f436861696e2d5048502f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/Digital-Currency-Research/Chain-PHP)

This library provides a simple PHP interface to the [Chain Bitcoin API](https://chain.com/).

[All methods](https://chain.com/docs) are supported including sending transactions and creating webhooks and webhook events. You will need to [sign up to Chain](https://chain.com/) for a free API Key and Key Secret as they are required to authenticate requests.

### Installing via Composer

[](#installing-via-composer)

The recommended way to install the library is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Chain-PHP as a dependency
php composer.phar require cbix/chain-php:dev-master
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

### Setup

[](#setup)

You will need to reference your API Key ID and API Key Secret as provided by Chain to authenticate your requests. There is an optional third parameter, which if set to true will use the Bitcoin Testnet3 block chain. It defaults to using the Bitcoin Mainnet if not specified or set to false.

```
$chain = Chain::make($key, $secret, false);

```

### Return Values

[](#return-values)

Please see the [Chain documentation](https://chain.com/docs/v1/) for the various return objects for each method call.

- [Bitcoin Address Object](https://chain.com/docs#bitcoin-address-transactions)
- [Bitcoin Transaction Object](https://chain.com/docs#bitcoin-address-transactions)
- Output Object array
- OP\_RETURN Object.
- [Webhook URL Object](https://chain.com/docs/#object-webhooks)

### Address

[](#address)

Further details are available in the examples included. Where the API accepts multiple addresses you should provide an array of addresses.

```
$single_address = $chain->get_address('17x23dNjXJLzGMev6R63uyRhMWP1VHawKc');
$multiple_addresses = $chain->get_address(['17x23dNjXJLzGMev6R63uyRhMWP1VHawKc', '1EX1E9n3bPA1zGKDV5iHY2MnM7n5tDfnfH']);
$transactions = $chain->get_transactions('17x23dNjXJLzGMev6R63uyRhMWP1VHawKc');
$unspents = $chain->get_address_unspents('17x23dNjXJLzGMev6R63uyRhMWP1VHawKc');
$op_returns = $chain->get_address_op_returns('17x23dNjXJLzGMev6R63uyRhMWP1VHawKc');

```

### Transaction

[](#transaction)

You may send a transaction to the blockchain but you will need to determine the appropriate hex representation of the signed transaction. In order to achieve this please consider using the [bitcoin-lib-php library](https://github.com/Bit-Wasp/bitcoin-lib-php).

```
$transaction = $chain->get_transaction('0f40015ddbb8a05e26bbacfb70b6074daa1990b813ba9bc70b7ac5b0b6ee2c45');
$op_return = $chain->get_transaction_op_return('0f40015ddbb8a05e26bbacfb70b6074daa1990b813ba9bc70b7ac5b0b6ee2c45');
$send = $chain->send_transaction('0100000001ec...');

```

### Block

[](#block)

The get\_block and get\_block\_op\_returns will accept either a block hash or block height as an input.

```
$block = $chain->get_block('00000000000000009cc33fe219537756a68ee5433d593034b6dc200b34aa35fa');
$latest_block = $chain->get_latest_block();
$block_op_returns = $chain->get_block_op_returns('00000000000000009cc33fe219537756a68ee5433d593034b6dc200b34aa35fa');

```

Webhooks
--------

[](#webhooks)

### Setup

[](#setup-1)

For webhooks you will need to create a webhook client passing your API Key and API Key Secret.

```
$webhook = Chain::webhook($key, $secret);

```

When creating webhooks the id attribute may be specified or if not provided will be generated by the Chain API.

```
$create_webhook = $webhook->create_webhook('https://username:password@your-server-url.com', 'FFA21991-5669-4728-8C83-74DEC4C93A4A');
$list_webhooks = $webhook->list_webhooks();
$update_webhook = $webhook->update_webhook('FFA21991-5669-4728-8C83-74DEC4C93A4A', 'https://username:password@your-server-url.com');
$delete_webhook = $webhook->delete_webhook('FFA21991-5669-4728-8C83-74DEC4C93A4A');

$options = [
    'event' => 'address-transaction',
    'block_chain' => 'bitcoin',
    'address' => '1...',
    'confirmations' => 1
];
$create_webhook_event = $webhook->create_webhook_event('FFA21991-5669-4728-8C83-74DEC4C93A4A', $options);

$list_webhook_events = $webhook->list_webhook_events('FFA21991-5669-4728-8C83-74DEC4C93A4A');
$delete_webhook_event = $webhook->delete_webhook_event('FFA21991-5669-4728-8C83-74DEC4C93A4A');

```

Exceptions
----------

[](#exceptions)

If there are any issues during the API request a ChainException or ChainWebhookException will be thrown which can be caught and managed according to your application needs.

```
try {
    $latest_block = $chain->get_latest_block();
    echo $latest_block->block_id;
} catch (ChainException $e) {
    //There was an error more information in $e->getMessage();
    var_dump($e->getMessage());
}

```

Unit Tests
----------

[](#unit-tests)

This library uses PHPUnit for unit testing. In order to run the unit tests, you'll first need to install the dependencies of the project using Composer: `php composer.phar install --dev`. You can then run the tests using `vendor/bin/phpunit`. The library comes with a set of mocked responses from the Chain API for running the unit tests.

Contributions
-------------

[](#contributions)

Patches, bug fixes, feature requests, and pull requests are welcome.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/947d18667b95c03befacd5f20dae7127b954f2cefcbc17e30b8bf031c23ba194?d=identicon)[garethtdavies](/maintainers/garethtdavies)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/cbix-chain-php/health.svg)

```
[![Health](https://phpackages.com/badges/cbix-chain-php/health.svg)](https://phpackages.com/packages/cbix-chain-php)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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