phplockchain - A Blockchain in PHP
I implemented this blockchain to better understand the blockchain technology. This program is intended for educational and learning purposes, not for use in production environments!
The intention was to keep the structure of the project simple in order to facilitate learning and understanding what is happening in a blockchain.
Check out this repository and install the dependencies using composer:
$ git clone https://github.com/mattsches/phplockchain.git . $ cd phplockchain $ composer install
To start a (master) node, open a terminal and run
$ php src/node.php -p 5001 -d 4 -m
-p is the port number,
-d the difficulty (
4 is default, be careful not to set it too high), and
-m means it's the master node. Ommitting
-m means running as a regular node without a copy of the blockchain currently.
You can then send requests to the node through its API using Postman, CURL, or your favorite tool.
TODO: Add API docs.
If you find an error in my blockchain implementation, please report an issue or open a pull request.
If you think any part of the program can be simplified or changed so it will be easier to comprehend, don't hesitate to offer your thoughts.
There are central concepts of a blockchain that have not been implemented here, but probably should be added; some of these are:
- Validation of (the signature of) transactions
- Broadcasting transactions to peer nodes
- Broadcasting freshly mined block to peer nodes and negotiating consensus
- Adding a browser GUI for interaction with the nodes
Inspired by and based on the following resources: