PHP code example of blockcypher / php-client

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

    

blockcypher / php-client example snippets



// Autoload the SDK Package. Installed via direct download.
ire 'vendor/autoload.php';

use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Rest\ApiContext;
use BlockCypher\Api\Address;

// Provide your Token. Replace the given one with your app Token
// https://accounts.blockcypher.com/dashboard
$token = 'c0afcccdde5081d6429de37d16166ead';

// SDK config
$config = array(
    'mode' => 'sandbox',
    'log.LogEnabled' => true,
    'log.FileName' => 'BlockCypher.log',
    'log.LogLevel' => 'DEBUG', // PLEASE USE 'INFO' LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
    'validation.level' => 'log',
);

$apiContext = ApiContext::create(
    'main', 'btc', 'v1',
    new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'),
    $config
);


use BlockCypher\Client\AddressClient;

$addressClient = new AddressClient($apiContext);
$address = $addressClient->get('1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD');

echo "JSON Address: " . $address->toJson() . "\n";
var_dump($address);


$microTXClient = new MicroTXClient($apiContext);

try {
    $microTX = $microTXClient->sendSigned(
        "2c2cc015519b79782bd9c5af66f442e808f573714e3c4dc6df7d79c183963cff", // private key
        "C4MYFr4EAdqEeUKxTnPUF3d3whWcPMz1Fi", // to address
        10000 // value (satoshis)
    );
} catch (\Exception $e) {
    echo "There was an error sending the microtx.\n";
}