2017 © Pedro Peláez
 

library blockchain-wallet-api

Zend Framework 2 (ZF2) client library for blockchain wallet api. Configure request, call the service and access the response data via objects.

image

sandrokeil/blockchain-wallet-api

Zend Framework 2 (ZF2) client library for blockchain wallet api. Configure request, call the service and access the response data via objects.

  • Tuesday, August 25, 2015
  • by sandrokeil
  • Repository
  • 2 Watchers
  • 8 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Blockchain Wallet Api module for Zend Framework 2

You want an easy client for the blockchain wallet api?, (*1)

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

You want to display bitcoin in mBTC or uBTC?, (*3)

This module comes to the rescue!, (*4)

Build Status Scrutinizer Code Quality Coverage Status HHVM Status SensioLabsInsight Latest Stable Version Dependency Status Total Downloads License, (*5)

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., (*6)

  • 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., (*7)

Put the following into your composer.json, (*8)

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

Then add Sake\BlockchainWalletApi to your ./config/application.config.php., (*9)

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

Documentation

Please refer to blockchain wallet api documentation for request details., (*11)

These request classes matches to api methods, (*12)

  • 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:, (*13)

<?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., (*14)

  • 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., (*15)

Send bitcoins

Here is an example how to send a transaction to a bitcoin address:, (*16)

<?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., (*17)

<?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:, (*18)

<?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:, (*19)

<?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

The Versions

25/08 2015

dev-develop

dev-develop https://github.com/sandrokeil/BlockchainWalletApi

Zend Framework 2 (ZF2) client library for blockchain wallet api. Configure request, call the service and access the response data via objects.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api payment zf2 client bitcoin blockchain webservice wallet blockchain wallet api