PHP code example of tkijewski / php-lnrpc

1. Go to this page and download the library: Download tkijewski/php-lnrpc 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/ */

    

tkijewski / php-lnrpc example snippets


$ sudo apt-get install php-dev php-pear zlib1g-dev zip unzip
$ pecl install grpc
$ sudo sh -c "echo 'extension=grpc.so' >> /etc/php/7.2/cli/php.ini" #depends on PHP version you are using. Add this line in the ini file

composer 



putenv('GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA');

/.lnd/data/chain/bitcoin/mainnet/admin.macaroon';

$cert = file_get_contents($certPath);
$macaroon = file_get_contents($macaroonPath);
$callback = function ($metadata) use ($macaroon) {
        return ['macaroon' => [bin2hex($macaroon)]];
    };

$credentials = \Grpc\ChannelCredentials::createSsl($cert);
$x = new \Lnrpc\LightningClient('127.0.0.1:10009',['credentials'=>$credentials,'update_metadata'=>$callback]);
$gir = new \Lnrpc\WalletBalanceRequest();
$result = $x->WalletBalance($gir);
echo "Balance:".$result->wait()[0]->getTotalBalance();


//EXAMPLE BY @MrHash

use Invoicesrpc\InvoicesClient;
use Lnrpc\LightningClient;

final class LndGrpcClient
{
    /** @var LightningClient */
    public $lnrpc;

    /** @var InvoicesClient */
    public $invoicesrpc;

    public function __construct(string $endpoint, array $options)
    {
        $this->lnrpc = new LightningClient($endpoint, $options); //$options example seen in Basic Usage
        $this->invoicesrpc = new InvoicesClient($endpoint, $options); //$options example seen in Basic Usage
    }
}