{"id":22018346,"url":"https://github.com/flavienbwk/blockchain-php","last_synced_at":"2025-05-07T03:27:32.838Z","repository":{"id":50277378,"uuid":"136805920","full_name":"flavienbwk/blockchain-php","owner":"flavienbwk","description":"An object-oriented PHP library for creating a blockchain easily.","archived":false,"fork":false,"pushed_at":"2019-08-12T07:55:35.000Z","size":10,"stargazers_count":34,"open_issues_count":0,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-16T07:20:42.607Z","etag":null,"topics":["blockchain","composer","oop","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flavienbwk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-10T12:13:08.000Z","updated_at":"2023-11-18T11:54:30.000Z","dependencies_parsed_at":"2022-09-03T14:30:39.744Z","dependency_job_id":null,"html_url":"https://github.com/flavienbwk/blockchain-php","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fblockchain-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fblockchain-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fblockchain-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fblockchain-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flavienbwk","download_url":"https://codeload.github.com/flavienbwk/blockchain-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252805924,"owners_count":21807113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","composer","oop","php"],"created_at":"2024-11-30T05:11:58.155Z","updated_at":"2025-05-07T03:27:32.795Z","avatar_url":"https://github.com/flavienbwk.png","language":"PHP","readme":"# PHP Blockchain\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://choosealicense.com/licenses/mit/\" alt=\"MIT License\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/license/mashape/apistatus.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nAn object-oriented PHP library for creating a simple blockchain easily.\n\nOriginal code (august 2015) by Marty Anstey (https://marty.anstey.ca/), on [Github](https://github.com/rhondle/BlockChain).  \nThe code has been improved and adapted to an object-oriented library.\n\n## Characteristics\n\n- SHA256 hash algorithm.\n- Record any data.\n- File-based (the blockchain lives in two files only).\n- PHP \u003e= 7.1 (verified).\n\n## Installation\n\n````bash\ncomposer require flavienbwk/blockchain-php\n````\n\n## Usage\n\n### Adding a block.\n\nOur blockchain will be saved in the `blockchain.dat` file for the example.\n\n````php\nrequire 'vendor/autoload.php';\n\n$Blockchain = new \\flavienbwk\\BlockchainPHP\\Blockchain();\n$block = $Blockchain-\u003eaddBlock(\"blockchain.dat\", \"What you want to put in the blockchain\");\n````\n\nYou can now get the data of your block :\n\n````php\n$block-\u003ehasError();     // Returns true or false if there was an error while adding the block.\n$block-\u003egetMessage();   // Returns the error message.\n$block-\u003egetHash();      // Returns the hash (SHA256) of the block.\n$block-\u003egetPrevHash();  // Returns the hash (SHA256) of the block added before this one.\n$block-\u003egetData();      // Returns the data stored in the block.\n$block-\u003egetPosition();  // Returns the height/position of the block in the blockchain.\n$block-\u003egetJson();      // Returns a JSON associative array with all the data of the block.\n// ...\n// Go to /src/Block.php to see all the getters.\n````\n\nYou can get the data of one block by its hash or previous hash block :\n\n````php\n$Blockchain-\u003egetBlockByHash(\"blockchain.dat\", \"INSERT_THE_BLOCK_HASH_HERE\");\n$Blockchain-\u003egetBlockByPrevHash(\"blockchain.dat\", \"INSERT_THE_BLOCK_HASH_HERE\");\n````\n\n### Printing all your blockchain.\n\n````php\n$Blockchain = new \\flavienbwk\\BlockchainPHP\\Blockchain();\n\n$all = $Blockchain-\u003egetBlockchain(\"blockchain.dat\");\nvar_dump($all);\n````\n\nAs 3 blocks have been added, it will display :\n\n````php\n[  \n   {  \n      \"position\":1,\n      \"header\":127,\n      \"magic\":\"d5e8a97f\",\n      \"version\":1,\n      \"timestamp\":1528658690,\n      \"prevhash\":\"0000000000000000000000000000000000000000000000000000000000000000\",\n      \"hash\":\"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d\",\n      \"datalen\":15,\n      \"data\":\"{\\\"id\\\":\\\"BLABLA\\\"}\"\n   },\n   {  \n      \"position\":2,\n      \"header\":127,\n      \"magic\":\"d5e8a97f\",\n      \"version\":1,\n      \"timestamp\":1528658691,\n      \"prevhash\":\"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d\",\n      \"hash\":\"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710\",\n      \"datalen\":15,\n      \"data\":\"{\\\"id\\\":\\\"BLABLA\\\"}\"\n   },\n   {  \n      \"position\":3,\n      \"header\":127,\n      \"magic\":\"d5e8a97f\",\n      \"version\":1,\n      \"timestamp\":1528658692,\n      \"prevhash\":\"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710\",\n      \"hash\":\"555905b331a019bed206b772dd191e6ad2e7cb263e6c9e610222c1afd4c8b0c9\",\n      \"datalen\":15,\n      \"data\":\"{\\\"id\\\":\\\"BLABLA\\\"}\"\n   }\n]\n````\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavienbwk%2Fblockchain-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflavienbwk%2Fblockchain-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavienbwk%2Fblockchain-php/lists"}