PHP code example of andkom / php-bitcoin-blockchain

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

    

andkom / php-bitcoin-blockchain example snippets


$databaseReader = new DatabaseReader('/path/to/bitcoin');

// read ordered blocks
foreach ($databaseReader->readBlocks() as $block) {
}

// read unordered blocks
foreach ($databaseReader->readBlocksUnordered() as $block) {
}

// read UTXO 
foreach ($databaseReader->getChainstate()->read() as $utxo) {
}

// get block by hash
$block = $databaseReader->getBlockByHash('binary hash in little endian'); 

// get block by height
$block = $databaseReader->getBlockByHeight(12345);

// get best block hash
$hash = $databaseReader->getChainstate()->getBestBlock();

composer