https://github.com/andkom/php-bitcoin-blockchain
A simple PHP library for reading Bitcoin blockchain database.
https://github.com/andkom/php-bitcoin-blockchain
bitcoin bitcoin-blockchain bitcoin-blocks bitcoin-protocol php php-library
Last synced: 8 months ago
JSON representation
A simple PHP library for reading Bitcoin blockchain database.
- Host: GitHub
- URL: https://github.com/andkom/php-bitcoin-blockchain
- Owner: andkom
- License: mit
- Created: 2018-09-09T18:55:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-14T14:11:47.000Z (over 6 years ago)
- Last Synced: 2025-04-12T00:42:42.858Z (about 1 year ago)
- Topics: bitcoin, bitcoin-blockchain, bitcoin-blocks, bitcoin-protocol, php, php-library
- Language: PHP
- Size: 74.2 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## PHP Bitcoin Blockchain Parser
A PHP implementation of Bitcoin blockchain database parser.
### Features:
- Parse unordered block data
- Parse ordered block data
- Parse block index
- Parse chain state (UTXO database)
### Requirements
- PHP >= 7.1
- Bitcoin Core >= 0.15.1
- leveldb >= 1.20
- php-leveldb >= 0.2.1
- php-gmp >= 7.1
### Installation
```
composer require andkom/php-bitcoin-blockchain
```
### Examples
```php
$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();
```
See more examples in the examples dir.
### LevelDB installation
Ubuntu/Debian:
```bash
apt-get install libleveldb-dev
pecl install leveldb-0.2.1
```
Mac OS:
```bash
brew install leveldb
pecl install leveldb-0.2.1
```
Or compile from source:
```bash
git clone https://github.com/google/leveldb.git
cd leveldb
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
make install
cd ../../
git clone https://github.com/reeze/php-leveldb.git
cd php-leveldb
phpize
./configure --with-leveldb
make
make install
```
Make sure you've enabled leveldb.so extension in your php.ini.