{"id":13394439,"url":"https://github.com/lhartikk/naivechain","last_synced_at":"2025-05-14T18:03:15.628Z","repository":{"id":45730875,"uuid":"70409315","full_name":"lhartikk/naivechain","owner":"lhartikk","description":"A blockchain implementation in 200 lines of code","archived":false,"fork":false,"pushed_at":"2020-04-13T09:14:37.000Z","size":59,"stargazers_count":5285,"open_issues_count":32,"forks_count":1147,"subscribers_count":280,"default_branch":"master","last_synced_at":"2025-04-11T10:00:34.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lhartikk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-09T14:43:06.000Z","updated_at":"2025-04-08T10:23:42.000Z","dependencies_parsed_at":"2022-09-22T21:41:57.530Z","dependency_job_id":null,"html_url":"https://github.com/lhartikk/naivechain","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/lhartikk%2Fnaivechain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lhartikk%2Fnaivechain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lhartikk%2Fnaivechain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lhartikk%2Fnaivechain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lhartikk","download_url":"https://codeload.github.com/lhartikk/naivechain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198452,"owners_count":22030964,"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-07-30T17:01:19.761Z","updated_at":"2025-05-14T18:03:10.620Z","avatar_url":"https://github.com/lhartikk.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Blockchain"],"sub_categories":[],"readme":"# Naivechain - a blockchain implementation in 200 lines of code\n\n### Motivation\nAll the current implementations of blockchains are tightly coupled with the larger context and problems they (e.g. Bitcoin or Ethereum) are trying to solve. This makes understanding blockchains a necessarily harder task, than it must be. Especially source-code-wisely. This project is an attempt to provide as concise and simple implementation of a blockchain as possible.\n\n \n### What is blockchain\n[From Wikipedia](https://en.wikipedia.org/wiki/Blockchain_(database)) : Blockchain is a distributed database that maintains a continuously-growing list of records called blocks secured from tampering and revision.\n\n### Key concepts of Naivechain\nCheck also [this blog post](https://medium.com/@lhartikk/a-blockchain-in-200-lines-of-code-963cc1cc0e54#.dttbm9afr5) for a more detailed overview of the key concepts\n* HTTP interface to control the node\n* Use Websockets to communicate with other nodes (P2P)\n* Super simple \"protocols\" in P2P communication\n* Data is not persisted in nodes\n* No proof-of-work or proof-of-stake: a block can be added to the blockchain without competition\n\n\n![alt tag](naivechain_blockchain.png)\n\n![alt tag](naivechain_components.png)\n\n\n### Naivecoin\nFor a more extensive tutorial about blockchains, you can check the project [Naivecoin](https://lhartikk.github.io/). It is based on Naivechain and implements for instance Proof-of-work, transactions and wallets.\n\n### Quick start\n(set up two connected nodes and mine 1 block)\n```\nnpm install\nHTTP_PORT=3001 P2P_PORT=6001 npm start\nHTTP_PORT=3002 P2P_PORT=6002 PEERS=ws://localhost:6001 npm start\ncurl -H \"Content-type:application/json\" --data '{\"data\" : \"Some data to the first block\"}' http://localhost:3001/mineBlock\n```\n\n### Quick start with Docker\n(set up three connected nodes and mine a block)\n###\n```sh\ndocker-compose up\ncurl -H \"Content-type:application/json\" --data '{\"data\" : \"Some data to the first block\"}' http://localhost:3001/mineBlock\n```\n\n### HTTP API\n##### Get blockchain\n```\ncurl http://localhost:3001/blocks\n```\n##### Create block\n```\ncurl -H \"Content-type:application/json\" --data '{\"data\" : \"Some data to the first block\"}' http://localhost:3001/mineBlock\n``` \n##### Add peer\n```\ncurl -H \"Content-type:application/json\" --data '{\"peer\" : \"ws://localhost:6001\"}' http://localhost:3001/addPeer\n```\n#### Query connected peers\n```\ncurl http://localhost:3001/peers\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flhartikk%2Fnaivechain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flhartikk%2Fnaivechain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flhartikk%2Fnaivechain/lists"}