2017 © Pedro Peláez
 

library php-litecoinrpc

Litecoin JSON-RPC client based on GuzzleHttp

image

majestic/php-litecoinrpc

Litecoin JSON-RPC client based on GuzzleHttp

  • Wednesday, February 21, 2018
  • by majestic84
  • Repository
  • 1 Watchers
  • 3 Stars
  • 320 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 33 Forks
  • 0 Open issues
  • 19 Versions
  • 237 % Grown

The README.md

Simple Litecoin JSON-RPC client based on GuzzleHttp

About

This project is based on php-bitcoinrpc project - fully unit-tested Litecoin JSON-RPC client powered by GuzzleHttp., (*1)

Installation

Run php composer.phar require majestic/php-litecoinrpc in your project directory or add following lines to composer.json, (*2)

"require": {
    "majestic/php-litecoinrpc": "^2.0"
}

and run php composer.phar update., (*3)

Requirements

PHP 7.0 or higher (should also work on 5.6, but this is unsupported), (*4)

Usage

Create new object with url as parameter, (*5)

use Majestic\Litecoin\Client as LitecoinClient;

$litecoind = new LitecoinClient('http://rpcuser:rpcpassword@localhost:9332/');

or use array to define your litecoind settings, (*6)

use Majestic\Litecoin\Client as LitecoinClient;

$litecoind = new LitecoinClient([
    'scheme' => 'http',                 // optional, default http
    'host'   => 'localhost',            // optional, default localhost
    'port'   => 9332,                   // optional, default 9332
    'user'   => 'rpcuser',              // required
    'pass'   => 'rpcpassword',          // required
    'ca'     => '/etc/ssl/ca-cert.pem'  // optional, for use with https scheme
]);

Then call methods defined in Litecoin Core API Documentation with magic:, (*7)

/**
 * Get block info.
 */
$block = $litecoind->getBlock('9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8');

$block('hash')->get();     // 9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8
$block['height'];          // 1298009 (array access)
$block->get('tx.0');       // a8971eaf8dfda3ee5dd20b3de3fb6c22e936339bbb53f8fa0f2379941ac5ff3f
$block->count('tx');       // 26
$block->has('version');    // key must exist and CAN NOT be null
$block->exists('version'); // key must exist and CAN be null
$block->contains(0);       // check if response contains value
$block->values();          // array of values
$block->keys();            // array of keys
$block->random(1, 'tx');   // random block txid
$block('tx')->random(2);   // two random block txid's
$block('tx')->first();     // txid of first transaction
$block('tx')->last();      // txid of last transaction

/**
 * Send transaction.
 */
$result = $litecoind->sendToAddress('LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY', 0.1);
$txid = $result->get();

/**
 * Get transaction amount.
 */
$result = $litecoind->listSinceBlock();
$totalAmount = $result->sum('transactions.*.amount');
$totalSatoshi = LitecoinClient::toSatoshi($totalAmount);

To send asynchronous request, add Async to method name:, (*8)

use Majestic\Litecoin\LitecoindResponse;

$promise = $litecoind->getBlockAsync(
    '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8',
    function (LitecoindResponse $success) {
        //
    },
    function (\Exception $exception) {
        //
    }
);

$promise->wait();

You can also send requests using request method:, (*9)

/**
 * Get block info.
 */
$block = $litecoind->request('getBlock', '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8');

$block('hash');            // 9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8
$block['height'];          // 1298009 (array access)
$block->get('tx.0');       // a8971eaf8dfda3ee5dd20b3de3fb6c22e936339bbb53f8fa0f2379941ac5ff3f
$block->count('tx');       // 26
$block->has('version');    // key must exist and CAN NOT be null
$block->exists('version'); // key must exist and CAN be null
$block->contains(0);       // check if response contains value
$block->values();          // get response values
$block->keys();            // get response keys
$block->random(1, 'tx');   // get random txid

/**
 * Send transaction.
 */
$result = $BTC->request('sendtoaddress', ['LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY', 0.06]);
$txid = $result->get();

or requestAsync method for asynchronous calls:, (*10)

use Majestic\Litecoin\LitecoindResponse;

$promise = $litecoind->requestAsync(
    'getBlock',
    '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8',
    function (LitecoindResponse $success) {
        //
    },
    function (\Exception $exception) {
        //
    }
);

$promise->wait();

Multi-Wallet RPC

You can use wallet($name) function to do a Multi-Wallet RPC call:, (*11)

/**
 * Get wallet2.dat balance.
 */
$balance = $litecoind->wallet('wallet2.dat')->getbalance();

$balance->get(); // 0.10000000

License

This product is distributed under MIT license., (*12)

Donations

If you like this project, you can donate Litecoins to LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY., (*13)

Thanks for your support!, (*14)

The Versions

21/02 2018

dev-master

9999999-dev https://github.com/majestic84/php-litecoinrpc

Litecoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar majestic84

api guzzle jsonrpc litecoin

19/10 2017

v2.0.2

2.0.2.0 https://github.com/majestic84/php-litecoinrpc

Litecoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar majestic84

api guzzle jsonrpc litecoin

21/08 2017

v2.0.1

2.0.1.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

17/08 2017

v2.0.0

2.0.0.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

17/08 2017

v2.0.0rc1

2.0.0.0-RC1 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

15/08 2017

v2.0.0beta1

2.0.0.0-beta1 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

15/08 2017

dev-analysis-z4yy6N

dev-analysis-z4yy6N https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

14/08 2017

dev-analysis-zO2AyJ

dev-analysis-zO2AyJ https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

13/08 2017

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

12/08 2017

v1.0.8

1.0.8.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

12/08 2017

dev-analysis-XaNJgm

dev-analysis-XaNJgm https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

12/08 2017

v1.0.7

1.0.7.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

05/02 2017

v1.0.6

1.0.6.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

31/01 2017

v1.0.5

1.0.5.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

21/01 2017

v1.0.4

1.0.4.0 https://github.com/denpamusic/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

21/01 2017

v1.0.3

1.0.3.0 https://github.com/denpamusic/php-bitapi

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

21/01 2017

v1.0.2

1.0.2.0 https://github.com/denpamusic/php-bitapi

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

20/01 2017

v1.0.1

1.0.1.0 https://github.com/denpamusic/php-bitapi

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc

20/01 2017

v1.0.0

1.0.0.0 https://github.com/denpamusic/php-bitapi

Bitcoin JSON-RPC client based on GuzzleHttp

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Paavilainen

api guzzle bitcoin jsonrpc