{"id":13958271,"url":"https://github.com/OpensourceBooks/blockchain","last_synced_at":"2025-07-20T23:30:52.635Z","repository":{"id":37626475,"uuid":"143727564","full_name":"OpensourceBooks/blockchain","owner":"OpensourceBooks","description":"开源教程：从零开始写区块链","archived":false,"fork":false,"pushed_at":"2018-12-22T00:14:26.000Z","size":263,"stargazers_count":531,"open_issues_count":3,"forks_count":123,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-11-28T01:34:26.095Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpensourceBooks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-06T12:47:04.000Z","updated_at":"2024-11-14T13:00:07.000Z","dependencies_parsed_at":"2022-07-09T17:00:24.035Z","dependency_job_id":null,"html_url":"https://github.com/OpensourceBooks/blockchain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/OpensourceBooks/blockchain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpensourceBooks%2Fblockchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpensourceBooks%2Fblockchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpensourceBooks%2Fblockchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpensourceBooks%2Fblockchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpensourceBooks","download_url":"https://codeload.github.com/OpensourceBooks/blockchain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpensourceBooks%2Fblockchain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266214653,"owners_count":23893932,"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":[],"created_at":"2024-08-08T13:01:27.581Z","updated_at":"2025-07-20T23:30:52.290Z","avatar_url":"https://github.com/OpensourceBooks.png","language":"Python","funding_links":[],"categories":["区块链、智能合约"],"sub_categories":["网络服务_其他"],"readme":"# blockchain 开源教程：从零开始写区块链\n\n### 介绍\n\n这个教程最终完成后，是一个支持物联网设备的专门用于追溯的无币区块链。\n\n目前区块链项目的名字还没有确定，但本教程一旦完成，该项目会立刻启动。\n\n### 说明\n\n\u003e 每个文件夹里都是一个课程，都有源码。\n\n\u003e 本教程目前由我本人来写，因用业余时间，因此不能保证每天都有更新。\n\n\u003e 为了保持简单，本教程用python做示例，大部分只用到 list、dict、json等对象，没有使用class。\n\n\u003e 因水平有限，我尽力把这件事做好，欢迎大家指教。\n\n### 安装\n\n```\nhttps://github.com/OpensourceBooks/blockchain.git\n```\n\n```\ncd blockchain\n```\n\n```\npip3 install -r requirements.txt\n```\n\n### 必要环境\n\n* python3\n* python3-pip3\n\n### 运行示例\n\n进入每个文件夹，运行:\n\n```\npython3 blockchain.py\n```\n\n### 简介\n\n区块链是一种由区块组成的链式结构。每个区块有自己唯一的hash值，也有上一个区块的hash值。区块一个一个链接，形成区块链。\n\n![blockchain](0/blockchain.svg)\n\n如果所示，这是区块链中数据不可篡改的关键。假设把block_1的内容给篡改了，那么block_1的hash就变化了。结果导致block_2的previous_hash和block_1的hash对不上，因此这个区块链就断裂了。\n\n![blockchain](0/blockchain_err.svg)\n\n本教程用来说明，如何用python语言来写一个区块链。在我开始写之前，我知道市面上已经有了一些教程，而且也有国外大牛写好了python区块链。但是我依然要写这本书，而且要用开源的方式。至于为什么用python，因为python使用方便，无需配置，而且方便用于各种IOT（物联网）设备上。\n\n### 课程\n\n[第0课、最简单的区块链](0/readme.md)\n\n[第1课、拥有index和时间戳的区块链](1/readme.md)\n\n[第2课、一个能在浏览器访问的区块链](2/readme.md)\n\n[第3课、一个信息上链的功能](3/readme.md)\n\n[第4课、增加一些条件查询的区块链](4/readme.md)\n\n[第5课、可以多节点同步的区块链](5/readme.md)\n\n[第6课、同步节点时进行验证](6/readme.md)\n\n[第7课、签名数据上链](7/readme.md)\n\n[第8课、区块链浏览器](8/readme.md)\n    * 8.1 在8的版本上进行了更改，结构更扁平化，为了日后做kv数据的持久化。\n[第9课、hash上链](9/readme.md)\n\n\u003e 说明：8.2 文件夹经过测试有问题，不能执行。 8.1 没有测试。8、9、10文件夹内的程序是ok的。\n\n### 赞赏\n\n\u003e 如果我的课程对你有帮助，欢迎赞赏。赞赏的钱将用于出版纸质书籍。\n\n\u003e 赞赏时请备注你的github帐号，我会罗列出来。\n\n\u003cimg src=\"images/wx.jpg\" width=\"350\" /\u003e\n\n### 交流\n\n微信：cr4fun\n\n知识星球\n\n\u003cimg src=\"images/xq.jpg\" width=\"350\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpensourceBooks%2Fblockchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOpensourceBooks%2Fblockchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpensourceBooks%2Fblockchain/lists"}