{"id":17347571,"url":"https://github.com/janasunrise/blockchain-python","last_synced_at":"2025-04-14T20:56:44.552Z","repository":{"id":55063049,"uuid":"313849111","full_name":"janaSunrise/blockchain-python","owner":"janaSunrise","description":"This is a implementation of a basic blockchain structure in python, with all the description, and documentation of it's working and things.","archived":false,"fork":false,"pushed_at":"2021-11-18T16:42:24.000Z","size":68,"stargazers_count":15,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T09:11:14.877Z","etag":null,"topics":["blockchain","blockchain-structure","hash","miners","proof","python","python3"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/janaSunrise.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":"2020-11-18T06:55:57.000Z","updated_at":"2025-02-15T14:59:16.000Z","dependencies_parsed_at":"2022-08-14T10:40:45.525Z","dependency_job_id":null,"html_url":"https://github.com/janaSunrise/blockchain-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janaSunrise%2Fblockchain-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janaSunrise%2Fblockchain-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janaSunrise%2Fblockchain-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janaSunrise%2Fblockchain-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janaSunrise","download_url":"https://codeload.github.com/janaSunrise/blockchain-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961186,"owners_count":21189991,"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","blockchain-structure","hash","miners","proof","python","python3"],"created_at":"2024-10-15T16:49:17.535Z","updated_at":"2025-04-14T20:56:44.528Z","avatar_url":"https://github.com/janaSunrise.png","language":"HTML","readme":"# Blockchain implementation using Python.\n\nThis is a implementation of a basic blockchain structure in python, with all the description, and\ndocumentation of it's working and things.\n\n**NOTE**: It used to be a basic interaction API for finding the hashs, POW and the info. Currently\nit's revamped into a full stack website with dummy payments mining and a better UI.\n\n## Definition, and Representation of Blockchain\n\nHere is the representation of a transaction in blockchain in Python.\n\n```python\nblock = {\n    'index': 1,\n    'timestamp': 1506057125.900785,\n    'transactions': [\n        {\n            'sender': \"8527147fe1f5426f9dd545de4b27ee00\",\n            'recipient': \"a77f5cdfa2934df3954a5c7c7da5df1f\",\n            'amount': 5,\n        }\n    ],\n    'proof': 324984774000,\n    'previous_hash': \"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824\"\n}\n```\n\nEach new block contains within itself, the hash of the previous Block. This is crucial because it’s what\ngives blockchains immutability. If an attacker corrupted an earlier Block in the chain then all subsequent\nblocks will contain incorrect hashes.\n\n### Creating new Blocks\n\nWhen our Blockchain is instantiated we'll need to seed it with a genesis block, a block with\nno predecessors. We’ll also need to add a \"proof\" to our genesis block which is the result of\nmining (or proof of work).\n\n### Understanding Proof of Work\n\nA Proof of Work algorithm (PoW) is how new Blocks are created or mined on the blockchain.\nThe goal of PoW is to discover a number which solves a problem. The number must be difficult to\nfind but easy to verify computationally speaking by anyone on the network.\nThis is the core idea behind Proof of Work.\n\nLet’s decide that the hash of some integer x multiplied by another y must end in 0.\nSo, `hash(x * y) = ac23dc...0` And for this simplified example, let’s fix `x = 5`.\nImplementing this in Python:\n\n```python\nfrom hashlib import sha256\n\nx = 5\ny = 0  # Y needs to be calculated\n\nwhile sha256(f'{x*y}'.encode()).hexdigest()[-1] != \"0\":\n    y += 1\n\nprint(f'The solution is y = {y}')\n```\n\nThe solution here is `y = 21`. Since, the produced hash ends in `0`:\n\n```\nhash(5 * 21) = 1253e9373e...5e3600155e860\n```\n\nIn Bitcoin, the Proof of Work algorithm is called **Hashcash**. And it’s not too different from our\nbasic example above. It’s the algorithm that miners race to solve in order to create a new block.\nIn general, the difficulty is determined by the number of characters searched for in a string.\nThe miners are then rewarded for their solution by receiving a coin in a transaction.\n\nThe network is able to easily verify their solution.\n\nThis is what the request for a transaction will look like. It’s what the user sends to the server:\n\n```json\n{\n  \"sender\": \"my address\",\n  \"recipient\": \"someone else's address\",\n  \"amount\": 5\n}\n```\n\n## Tech Stack used\n\n- `Flask` - A HTTP Gateway to expose our blockchain structure externally.\n- `Requests` - A medium to check the HTTP Endpoint request and return JSON response.\n\n## How to run the project?\n\n- Clone the repo: `git clone https://github.com/janaSunrise/blockchain-python`\n- Install pipenv: `pip3 install pipenv`\n- Make a env with Pipenv: `pipenv sync`\n- Run the servers:\n  - Run the miner server using `python -m frontend`\n  - Run the clients using `python -m client \u003cPORT-HERE\u003e`\n\nYou can visit the site, play with the server, client and more, OR Use postman to Play and Mess with the\nHTTP and JSON responses!\n\n\u003cdiv align=\"center\"\u003eMade by Sunrit Jana with ❤️\u003c/div\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanasunrise%2Fblockchain-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanasunrise%2Fblockchain-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanasunrise%2Fblockchain-python/lists"}