PHP code example of oprokidnev / bitcoind-php

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

    

oprokidnev / bitcoind-php example snippets


$command = new \Nbobtc\Command\Command('getinfo');
$client  = new \Nbobtc\Http\Client('https://username:password@localhost:18332');

/** @var \Nbobtc\Http\Message\Response */
$response = $client->sendCommand($command);

/** @var string */
$contents = $response->getBody()->getContents();

// No Parameters
$command = new Command('getinfo');

// One Parameter
$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');

// Multiple Parameters
$command = new Command('sendfrom', array('fromaccount', 'tobitcoinaddress', 'amount'));

$command = new Command('getblock', array('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'));
$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');

$driver = new \Nbobtc\Http\Driver\CurlDriver();
$driver
    ->addCurlOption(CURLOPT_VERBOSE, true)
    ->addCurlOption(CURLOPT_STDERR, '/var/logs/curl.err');

$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->withDriver($driver);

$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->getRequest()->withHeader('Connection', 'Keep-Alive');

$driver = new \Nbobtc\Http\Driver\CurlDriver();
$driver->addCurlOption(CURLOPT_CAINFO, '/path/to/cert');

$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->withDriver($driver);

$response = $client->sendCommand($command);
$output   = json_decode($response->getBody()->getContents(), true);

$response = $client->sendCommand($command);
$output   = json_decode($response->getBody()->getContents());