kemalevren/laravel-bitcoinrpc

Bitcoin JSON-RPC Service Provider for Laravel

v1.1.2 2018-03-06 16:06 UTC

This package is not auto-updated.

Last update: 2021-11-19 20:10:13 UTC


README

Latest Stable Version License Build Status Code Climate 68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64656e70616d757369632f6c61726176656c2d626974636f696e7270632f6261646765732f636f7665726167652e737667 Dependency Status

About

This package allows you to make JSON-RPC calls to Bitcoin Core JSON-RPC server from your laravel project. It's based on php-bitcoinrpc project - fully unit-tested Bitcoin JSON-RPC client powered by GuzzleHttp.

Installation

Run php composer.phar require denpa/laravel-bitcoinrpc in your project directory or add following lines to composer.json

"require": {
    "denpa/laravel-bitcoinrpc": "^1.1"
}

and run php composer.phar update.

Add Denpa\Bitcoin\Providers\ServiceProvider::class, line to the providers list somewhere near the bottom of your /config/app.php file.

'providers' => [
    ...
    Denpa\Bitcoin\Providers\ServiceProvider::class,
];

Publish config file by running php artisan vendor:publish --provider="Denpa\Bitcoin\ServiceProvider" in your project directory.

You might also want to add facade to $aliases array in /config/app.php.

'aliases' => [
    ...
    'Bitcoind' => Denpa\Bitcoin\Facades\Bitcoind::class,
];

I recommend you to use .env file to configure client. To connect to Bitcoin Core you'll need to add at least following parameters

BITCOIND_USER=(rpcuser from bitcoin.conf)
BITCOIND_PASSWORD=(rpcpassword from bitcoin.conf)

Requirements

  • PHP 7.0 or higher (should also work on 5.6, but this is unsupported)
  • Laravel 5.1 or higher

Usage

You can perform request to Bitcoin Core using any of methods listed below:

Helper Function

<?php

namespace App\Http\Controllers;

class BitcoinController extends Controller
{
  /**
   * Get block info.
   *
   * @return object
   */
   public function blockInfo()
   {
      $blockHash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
      $blockInfo = bitcoind()->getBlock($blockHash);
      return response()->json($blockInfo->get());
   }
}

Facade

<?php

namespace App\Http\Controllers;

use Bitcoind;

class BitcoinController extends Controller
{
  /**
   * Get block info.
   *
   * @return object
   */
   public function blockInfo()
   {
      $blockHash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
      $blockInfo = Bitcoind::getBlock($blockHash);
      return response()->json($blockInfo->get());
   }
}

Automatic Injection

<?php

namespace App\Http\Controllers;

use Denpa\Bitcoin\Client as BitcoinClient;

class BitcoinController extends Controller
{
  /**
   * Get block info.
   *
   * @param  BitcoinClient  $bitcoind
   * @return \Illuminate\Http\JsonResponse
   */
   public function blockInfo(BitcoinClient $bitcoind)
   {
      $blockHash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
      $blockInfo = $bitcoind->getBlock($blockHash);
      return response()->json($blockInfo->get());
   }
}

License

This product is distributed under MIT license.

Donations

If you like this project, you can donate Bitcoins to 13gkVWc3sdzpmCLkGkXXfPBwnh6ZXct947.

Thanks for your support!❤