{"id":42691848,"url":"https://github.com/j4steu/pocket-blockchain","last_synced_at":"2026-01-29T13:05:31.303Z","repository":{"id":181423336,"uuid":"298123133","full_name":"J4stEu/pocket-blockchain","owner":"J4stEu","description":"Creation of blockchain system on Python for further integration in different projects","archived":false,"fork":false,"pushed_at":"2023-07-15T13:47:11.000Z","size":5273,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-07-15T15:23:10.821Z","etag":null,"topics":["api","blockchain","blocks","chainstate","docker","flask","full-node","merkle-tree","postgresql","proof-of-work","python","transactions","vuejs","wallets"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/J4stEu.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,"governance":null}},"created_at":"2020-09-24T00:00:00.000Z","updated_at":"2023-07-15T15:23:12.611Z","dependencies_parsed_at":"2023-07-15T15:37:19.298Z","dependency_job_id":null,"html_url":"https://github.com/J4stEu/pocket-blockchain","commit_stats":null,"previous_names":["j4steu/pocket-blockchain"],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/J4stEu/pocket-blockchain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4stEu%2Fpocket-blockchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4stEu%2Fpocket-blockchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4stEu%2Fpocket-blockchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4stEu%2Fpocket-blockchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J4stEu","download_url":"https://codeload.github.com/J4stEu/pocket-blockchain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4stEu%2Fpocket-blockchain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28877890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","blockchain","blocks","chainstate","docker","flask","full-node","merkle-tree","postgresql","proof-of-work","python","transactions","vuejs","wallets"],"created_at":"2026-01-29T13:05:29.914Z","updated_at":"2026-01-29T13:05:31.294Z","avatar_url":"https://github.com/J4stEu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pocket-Blockchain\nPocket-Blockchain is a blockchain system built from scratch, developed for the further integration in different projects, understanding some blockchain concepts by using test stand or just having fun experiments.\n\n\n## \u003cins\u003eTech stack\u003c/ins\u003e\n- Python \u003cimg src=\"./projectDemo/stackImg/1.png\" width=\"15\"\u003e\n- Python Flask \u003cimg src=\"./projectDemo/stackImg/2.png\" width=\"20\"\u003e\n- Flask SQLAlchemy \u003cimg src=\"./projectDemo/stackImg/2.png\" width=\"20\"\u003e\n- PostgreSQL \u003cimg src=\"./projectDemo/stackImg/3.png\" width=\"20\"\u003e\n- Vite + Vue.js 3 + Vue router + Pinia \u003cimg src=\"./projectDemo/stackImg/4.png\" width=\"20\"\u003e\n- Gunicorn \u003cimg src=\"./projectDemo/stackImg/5.png\" width=\"20\"\u003e\n- Nginx \u003cimg src=\"./projectDemo/stackImg/6.png\" width=\"15\"\u003e\n- Docker + Docker Compose \u003cimg src=\"./projectDemo/stackImg/7.png\" width=\"20\"\u003e\n\n## \u003cins\u003eUnder the hood\u003c/ins\u003e\n### Chain component:\n - communication of all system components;\n - setting the initial system settings;\n - setting the complexity of creating blocks based on the PoW algorithm;\n - setting a reward for creating a new block based on the PoW algorithm.\n\n### Wallet component:\n - users creation;\n - users anonymity;\n - users storage. This item is implemented for informational and debugging purposes, however, in real conditions, there should not be any users storage;\n - serialization and deserialization of users. This item is implemented for informational and debugging purposes, however, in real conditions, there should not be any storage of users.\n\n### Transaction component:\n - transactions creation;\n - blocking users until transaction is confirmed;\n - placing transactions in a pool of unconfirmed transactions;\n - balance check;\n - signature of transactions;\n - verification of transaction signatures;\n - verification of ownership of transactions;\n - transaction authentication; \n - serialization and deserialization of transactions. \n\n### Block component:\n - creation of new blocks;\n - getting available blocks;\n - use of Proof of Work algorithm to create a unique block hash identifier;\n - confirmation of Proof of Work algorithm;\n - serialization and deserialization of data blocks.\n\n### Chainstate component:\n - processing of unspent transactions of system users - cache;\n - cache serialization and deserialization.\n\n### Merkle Tree component:\n - creation of a unique hash identifier for all transactions stored in the block.\n\n### DB and API component:\n - storage and processing of the system state;\n - providing API methods for interacting with the system.\n\n## \u003cins\u003eDatabase\u003c/ins\u003e\nA relational database is used to store the state of the system. Database tables have the following structure:\n - Table b - storage of data blocks;\n - Table l - storage of the hash identifier of the last block;\n - Table c - cache storage;\n - Table p - storage of a pool of unconfirmed transactions.\n\n## \u003cins\u003eAPI\u003c/ins\u003e\n```\n[GET]: /api/get_wallets - gell all wallets with balances.\n[GET]: /api/get_blocks - get all blocks.\n[GET]: /api/get_chainstate - get chainstate (cache - unspent transactions).\n[GET]: /api/get_pool - get transactions pool (unconfirmed transactions).\n\n[POST]: /api/new_wallet - creation of a new wallet.\n[POST] {from, to, amount}: /api/send - send sign units from someone to someone.\n[POST] {address, txAmount}: /api/mine_block - mine new block with amount of tranactions.\n[POST]: /api/reset_system - system reset with training data generation.\n```\n\n## \u003cins\u003eMethods\u003c/ins\u003e\n```python\nnew_wallet # create new wallet\n\ninit_system(address) # init system by address\n\nget_balance(address) # get user balance \n\nsend(from, to, amount) # send some amount if sign unit from someone to someone\n\nmine_block(amount) # mine block with amount of transactions specified\n\nshow_blocks # show all information of all blocks\n```\n\n## \u003cins\u003eUsage Example\u003c/ins\u003e\n```python\n# Example\n\n# Import BlockChain and db to create blockchain system instance\nfrom app.blockchain_app.blockchain import BlockChain\nfrom app.app import db\n\n# Create blockchain system instance by passing db instance\nbc = BlockChain(db)\n\n# Create wallets\naddress1 = bc.new_wallet()\naddress2 = bc.new_wallet()\naddress3 = bc.new_wallet()\naddress4 = bc.new_wallet()\naddress5 = bc.new_wallet()\naddress6 = bc.new_wallet()\naddress7 = bc.new_wallet()\naddress8 = bc.new_wallet()\n\n# Init blockchain system, 10 sign units (our coins) - reward\nbc.init_system(address1)\n\n# Get balance of address1.\n# address1 should have 10 sign units.\nbc.get_balance(address1)\n\n# We can send sign units that we have to someone.\n# All we need is to know the address. \n# That is how transactions are created and added to the pool - pool of unconfirmed transactions.\n# Once a new transaction is created and added to pool, you can not use your wallet to\n# create new transactions until it confirmed (added to a new block).\nbc.send(address1, address2, 3)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address3, 2)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address4, 1)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address5, 1)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address6, 1)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address7, 1)\nbc.mine_block(address1)\nbc.get_balance(address1)\n#\nbc.send(address1, address8, 1)\nbc.mine_block(address1)\nbc.get_balance(address1)\n\n# Sending sign units\nbc.send(address2, address1, 1)\nbc.send(address3, address1, 1)\nbc.send(address4, address1, 1)\nbc.send(address5, address1, 1)\nbc.send(address6, address1, 1)\nbc.send(address7, address1, 1)\nbc.send(address8, address1, 1)\n\n# After all (in this example) we have 7 transactions in pool from 7 different wallets.\n# We can create two blocks: one with 2 transactions, one with 3 transactions in a block (5 - default).\n# There will be 2 transactions in a pool (not verified).\nbc.mine_block(address2, 2)\nbc.mine_block(address2, 3)\n\n# Balances\nbc.get_balance(address1) # 75\nbc.get_balance(address2) # 22\nbc.get_balance(address3) # 1\nbc.get_balance(address4) # 0\nbc.get_balance(address5) # 0\nbc.get_balance(address6) # 0\nbc.get_balance(address7) # 1\nbc.get_balance(address8) # 1\n\n# Get all information about all blocks in blockchain system\nbc.show_blocks()\n```\n\n## \u003cins\u003eBuild\u003c/ins\u003e\nYou can build this project with Docker + Docker Compose by using [build.sh](./docker_build/build.sh) script:\n```bash\npwd\n.../pocket-blockchain\ncd docker_build\nsource build.sh\ndocker ps\n...  IMAGE                    PORTS                                       NAMES\n...  pocket_blockchain_app    0.0.0.0:5001-\u003e5001/tcp, :::5001-\u003e5001/tcp   app\n...  postgres                 0.0.0.0:5432-\u003e5432/tcp, :::5432-\u003e5432/tcp   db\n...  pocket_blockchain_nginx  0.0.0.0:80-\u003e80/tcp, :::80-\u003e80/tcp           nginx\n```\nOr by running this command from the [docker_build](./docker_build) directory:\n```bash\npwd\n.../pocket-blockchain\ncd docker_build\ndocker-compose --project-name pocket_blockchain up -d --build --force-recreate\ndocker ps\n...  IMAGE                    PORTS                                       NAMES\n...  pocket_blockchain_app    0.0.0.0:5001-\u003e5001/tcp, :::5001-\u003e5001/tcp   app\n...  postgres                 0.0.0.0:5432-\u003e5432/tcp, :::5432-\u003e5432/tcp   db\n...  pocket_blockchain_nginx  0.0.0.0:80-\u003e80/tcp, :::80-\u003e80/tcp           nginx\n```\n\n## \u003cins\u003eTest stand\u003c/ins\u003e\nAfter project build or start up you can use test stand. Just go to:\n```\nlocalhost\n```\nor\n```\n127.0.0.1\n```\nTest stand uses all supported API methods, so that you can try this system / interact with system.\n\nTest stand will look like this:\n\n\u003cimg src=\"./projectDemo/6.png\" \u003e\n\u003cimg src=\"./projectDemo/7.png\" \u003e\n\u003cimg src=\"./projectDemo/8.png\" \u003e\n\u003cimg src=\"./projectDemo/9.png\" \u003e\n\u003cimg src=\"./projectDemo/10.png\" \u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4steu%2Fpocket-blockchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj4steu%2Fpocket-blockchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4steu%2Fpocket-blockchain/lists"}