PHPackages                             flavienbwk/blockchain-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. flavienbwk/blockchain-php

ActivePackage

flavienbwk/blockchain-php
=========================

An object-oriented PHP library for creating a blockchain easily.

1.0.2.1(7y ago)3747710MITPHPPHP &gt;=7.0.0

Since Jun 10Pushed 6y ago5 watchersCompare

[ Source](https://github.com/flavienbwk/blockchain-php)[ Packagist](https://packagist.org/packages/flavienbwk/blockchain-php)[ Docs](https://github.com/flavienbwk/blockchain-php)[ RSS](/packages/flavienbwk-blockchain-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

PHP Blockchain
==============

[](#php-blockchain)

[![](https://camo.githubusercontent.com/850eae1099d2b05f53383473d7cd51f9bc1ab09b7d0d9e5122f1dd930efdcc6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e737667)](https://choosealicense.com/licenses/mit/)

An object-oriented PHP library for creating a simple blockchain easily.

Original code (august 2015) by Marty Anstey (), on [Github](https://github.com/rhondle/BlockChain).
The code has been improved and adapted to an object-oriented library.

Characteristics
---------------

[](#characteristics)

- SHA256 hash algorithm.
- Record any data.
- File-based (the blockchain lives in two files only).
- PHP &gt;= 7.1 (verified).

Installation
------------

[](#installation)

```
composer require flavienbwk/blockchain-php
```

Usage
-----

[](#usage)

### Adding a block.

[](#adding-a-block)

Our blockchain will be saved in the `blockchain.dat` file for the example.

```
require 'vendor/autoload.php';

$Blockchain = new \flavienbwk\BlockchainPHP\Blockchain();
$block = $Blockchain->addBlock("blockchain.dat", "What you want to put in the blockchain");
```

You can now get the data of your block :

```
$block->hasError();     // Returns true or false if there was an error while adding the block.
$block->getMessage();   // Returns the error message.
$block->getHash();      // Returns the hash (SHA256) of the block.
$block->getPrevHash();  // Returns the hash (SHA256) of the block added before this one.
$block->getData();      // Returns the data stored in the block.
$block->getPosition();  // Returns the height/position of the block in the blockchain.
$block->getJson();      // Returns a JSON associative array with all the data of the block.
// ...
// Go to /src/Block.php to see all the getters.
```

You can get the data of one block by its hash or previous hash block :

```
$Blockchain->getBlockByHash("blockchain.dat", "INSERT_THE_BLOCK_HASH_HERE");
$Blockchain->getBlockByPrevHash("blockchain.dat", "INSERT_THE_BLOCK_HASH_HERE");
```

### Printing all your blockchain.

[](#printing-all-your-blockchain)

```
$Blockchain = new \flavienbwk\BlockchainPHP\Blockchain();

$all = $Blockchain->getBlockchain("blockchain.dat");
var_dump($all);
```

As 3 blocks have been added, it will display :

```
[
   {
      "position":1,
      "header":127,
      "magic":"d5e8a97f",
      "version":1,
      "timestamp":1528658690,
      "prevhash":"0000000000000000000000000000000000000000000000000000000000000000",
      "hash":"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d",
      "datalen":15,
      "data":"{\"id\":\"BLABLA\"}"
   },
   {
      "position":2,
      "header":127,
      "magic":"d5e8a97f",
      "version":1,
      "timestamp":1528658691,
      "prevhash":"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d",
      "hash":"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710",
      "datalen":15,
      "data":"{\"id\":\"BLABLA\"}"
   },
   {
      "position":3,
      "header":127,
      "magic":"d5e8a97f",
      "version":1,
      "timestamp":1528658692,
      "prevhash":"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710",
      "hash":"555905b331a019bed206b772dd191e6ad2e7cb263e6c9e610222c1afd4c8b0c9",
      "datalen":15,
      "data":"{\"id\":\"BLABLA\"}"
   }
]
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

2

Last Release

2878d ago

PHP version history (2 changes)1.0.2PHP ^7.1.0

1.0.2.1PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf48fb8ace8c19c216924df7905b102270ef754aa1ee024bcf48ce5e3f11cf43?d=identicon)[flavienbwk](/maintainers/flavienbwk)

---

Top Contributors

[![flavienbwk](https://avatars.githubusercontent.com/u/14158127?v=4)](https://github.com/flavienbwk "flavienbwk (12 commits)")

---

Tags

blockchaincomposeroopphpphpOOPblockchain

### Embed Badge

![Health badge](/badges/flavienbwk-blockchain-php/health.svg)

```
[![Health](https://phpackages.com/badges/flavienbwk-blockchain-php/health.svg)](https://phpackages.com/packages/flavienbwk-blockchain-php)
```

###  Alternatives

[manamine/php-eos-rpc-sdk

PHP SDK for the EOS RPC API

207.5k](/packages/manamine-php-eos-rpc-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
