PHP code example of amashukov / bchn-rpc-client-php

1. Go to this page and download the library: Download amashukov/bchn-rpc-client-php 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/ */

    

amashukov / bchn-rpc-client-php example snippets


use Amashukov\BchnRpc\BchnRpcClient;
use Amashukov\BchnRpc\Vo\BchAmount;
use Amashukov\BchnRpc\Vo\PsbtOutput;
use Amashukov\HttpClient\CurlClient;
use Nyholm\Psr7\Factory\Psr17Factory;

$psr17  = new Psr17Factory();
$node   = new BchnRpcClient(new CurlClient($psr17, $psr17, timeoutSeconds: 30), $psr17, $psr17, 'http://127.0.0.1:8332', 'rpcuser', 'rpcpassword');
$wallet = $node->withWallet('hot-wallet');

$node->getBlockchainInfo()->blocks;
$wallet->getWalletInfo()->balance->satoshis;

$address = $wallet->getNewAddress('deposit');
$info    = $wallet->getAddressInfo($address);        // ismine, hdkeypath

foreach ($wallet->listSinceBlock($lastBlock, 6)->transactions as $entry) {
    // $entry->txid, $entry->vout, $entry->address, $entry->amount->satoshis, $entry->confirmations
}

$utxos = $wallet->listUnspent(1, 9999999, [], true,