1. Go to this page and download the library: Download majestic/php-litecoinrpc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
majestic / php-litecoinrpc example snippets
composer.phar
composer.phar update
use Majestic\Litecoin\Client as LitecoinClient;
$litecoind = new LitecoinClient('http://rpcuser:rpcpassword@localhost:9332/');
/**
* 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);
use Majestic\Litecoin\LitecoindResponse;
$promise = $litecoind->getBlockAsync(
'9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8',
function (LitecoindResponse $success) {
//
},
function (\Exception $exception) {
//
}
);
$promise->wait();
/**
* 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();
use Majestic\Litecoin\LitecoindResponse;
$promise = $litecoind->requestAsync(
'getBlock',
'9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8',
function (LitecoindResponse $success) {
//
},
function (\Exception $exception) {
//
}
);
$promise->wait();