Zend Framework 2 (ZF2) client library for blockchain wallet api. Configure request, call the service and access the response data via objects.
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build
config
src
test
.gitignore
.scrutinizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.txt
Module.php
README-GIT.md
README.md
composer.json
phpunit.xml.dist

README.md

Blockchain Wallet Api module for Zend Framework 2

You want an easy client for the blockchain wallet api?

You want to configure request, call the service and access the response data via objects?

You want to display bitcoin in mBTC or uBTC?

This module comes to the rescue!

Build Status Scrutinizer Code Quality Coverage Status HHVM Status SensioLabsInsight Latest Stable Version Dependency Status Total Downloads License

Zend Framework 2 client library for blockchain wallet api. The usage is simple. Configure request, call the service and access the response data via objects.

  • Adapts To Your Needs. There are several possibilities to configure this module.
  • Well tested. Besides unit test and continuous integration/inspection this solution is also ready for production use.
  • Great foundations. Based on Zend Framework 2 and Easy Config
  • Every change is tracked. Want to know whats new? Take a look at CHANGELOG.md
  • Listen to your ideas. Have a great idea? Bring your tested pull request or open a new issue. See CONTRIBUTING.md

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.

Put the following into your composer.json

{
    "require": {
        "sandrokeil/blockchain-wallet-api": "~1.0"
    }
}

Then add Sake\BlockchainWalletApi to your ./config/application.config.php.

Copy config/blockchainwalletapi.local.php.dist to config/blockchainwalletapi.local.php and configure the credentials. Never commit this file to public repositories!

Documentation

Please refer to blockchain wallet api documentation for request details.

These request classes matches to api methods

  • Send => payment
  • SendMany => sendmany
  • WalletBalance => balance
  • ListAddresses => list
  • AddressBalance => address_balance
  • NewAddress => new_address
  • AddressArchive => archive_address
  • AddressUnarchive => unarchive_address
  • AutoConsolidateAddresses => auto_consolidate

Configuration

Connection parameters can be defined in the application configuration:

<?php

return array(
    'sake_bwa' => array(
        'connection' => array(
            'default' => array(
                'options' => array(
                    // see \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions for all configurations
                    'url' => 'https://blockchain.info/de/merchant/', // note on your country
                    'guid' => 'your My Wallet identifier (found on the login page)',
                    'main_password' => 'Your Main My wallet password',
                    'second_password' => 'Your second My Wallet password if double encryption is enabled',
                ),
                'client' => 'Service factory name for Http Client, Lazy-loads a Zend\Http\Client instance if none registered'
            )
        )
    )
);

Registered service names

  • sake_bwa.service.default: a \Sake\BlockchainWalletApi\Service\BlockchainWallet instance to send requests to the api
  • sake_bwa.service.response: a \Sake\BlockchainWalletApi\Service\ResponsePluginManager Service plugin manager to create responses via api method name
  • sake_bwa.service.request: a \Sake\BlockchainWalletApi\Service\RequestPluginManager Service plugin manager to create requests via api method name
  • sake_bwa.service.input_filter: a \Sake\BlockchainWalletApi\Service\InputFilterPluginManager Service plugin manager to create input filter via api method name
  • sake_bwa.service.hydrator: a \Zend\Stdlib\Hydrator\ClassMethods instance with strategies and filters for requests/responses

Registered view helper

To use this view helper you must add zendframework/zend-view to your composer dependencies.

  • satoshi: a \Zend\View\Helper\AbstractHelper instance which converts satoshi to other unit e.g. bitcoin

Examples

This module is very easy to use. However, these code snippets should help you to start.

Send bitcoins

Here is an example how to send a transaction to a bitcoin address:

<?php
use Sake\BlockchainWalletApi;

// $sl is the service locator
$blockchain = $sl->get('sake_bwa.service.default');

/* @var $request BlockchainWalletApi\Request\Send */
$request = $sl->get('sake_bwa.service.request')->get('payment');
// or
$request = new BlockchainWalletApi\Request\Send();

$request->setAmount(100000); // in satoshi
$request->setTo('1KwbP2sRHW7uDsxnW8sBbymVwnSsm8cFXC');

try {
    // validate request
    if ($blockchain->isValid($request)) {
        /* @var $response BlockchainWalletApi\Response\Send */
        $response = $service->send($request);
        // access to response data
        $transactionHash = $response->getTxHash();
    }
} catch (BlockchainWalletApi\Exception\ExceptionInterface $exception) {
    // error handling
}

Send bitcoins to multiple addresses

Here is an example how to send a transaction to multiple recipients in the same transaction.

<?php
use Sake\BlockchainWalletApi;

// $sl is the service locator
$blockchain = $sl->get('sake_bwa.service.default');

/* @var $request BlockchainWalletApi\Request\SendMany */
$request = $sl->get('sake_bwa.service.request')->get('sendmany');
// or
$request = new BlockchainWalletApi\Request\SendMany();

$request->setRecipients(
    array(
        new BlockchainWalletApi\Request\Recipient('1BzHqGWhdpXyLqiYkAT7sasfCoffYo79tT', 10000),
        new BlockchainWalletApi\Request\Recipient('1NqH4QkkjDErD9TNC7arDQVMv4zKgfCzmb', 10000),
    )
);

try {
    // validate request
    if ($blockchain->isValid($request)) {
        /* @var $response BlockchainWalletApi\Response\SendMany */
        $response = $service->send($request);
        // access to response data
        $transactionHash = $response->getTxHash();
    }
} catch (BlockchainWalletApi\Exception\ExceptionInterface $exception) {
    // error handling
}

Get wallet balance

Here is an example how to retrieve wallet balance:

<?php
use Sake\BlockchainWalletApi;

// $sl is the service locator
/* @var $blockchain BlockchainWalletApi\Service\BlockchainWallet */
$blockchain = $sl->get('sake_bwa.service.default');

/* @var $request BlockchainWalletApi\Request\WalletBalance */
$request = $sl->get('sake_bwa.service.request')->get('balance');
// or
$request = new BlockchainWalletApi\Request\WalletBalance();

try {
    // validate request
    if ($blockchain->isValid($request)) {
        /* @var $response BlockchainWalletApi\Response\WalletBalance */
        $response = $blockchain->send($request);
        // access to response data
        $balance = $response->getBalance(); // in satoshi
    }
} catch (BlockchainWalletApi\Exception\ExceptionInterface $exception) {
    // error handling
}

Using view helper to convert satoshi to other unit e.g. bitcoins

Here is an example how to use satoshi view helper to convert satoshi to an other unit:

<?php
// assume we are in a template

/* @var $response \Sake\BlockchainWalletApi\Response\WalletBalance */
echo $this->satoshi($response->getBalanace(), 'BTC'); // Bitcoin
// or
echo $this->satoshi($response->getBalanace(), 'mBTC'); // Milli Bits
// or
echo $this->satoshi($response->getBalanace(), 'uBTC'); // Micro Bitcoin