Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 6 hours 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 (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-14T14:11:47.000Z (almost 5 years ago)
- Last Synced: 2024-07-26T18:50:00.556Z (4 months ago)
- Topics: bitcoin, bitcoin-blockchain, bitcoin-blocks, bitcoin-protocol, php, php-library
- Language: PHP
- Size: 74.2 KB
- Stars: 13
- Watchers: 3
- 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.