Blockchain implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ポール ウェッブ c8ebb720aa Updated README 9 months ago
.gitignore Initial commit 9 months ago Updated README 9 months ago
main.js Initial commit 9 months ago
naivechain_blockchain.png Added README images 9 months ago
naivechain_components.png Added README images 9 months ago
package.json Initial commit 9 months ago


Blockchain implementation

Forked from here (sans Docker) and includes improvements from here and here.

Ideally, you would not have everything done in one file but this is just for learning purposes. The rest of this README is copied from the source.


All 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.

What is blockchain

From Wikipedia: Blockchain is a distributed database that maintains a continuously-growing list of records called blocks secured from tampering and revision.

Key concepts of Naivechain

Check also this blog post for a more detailed overview of the key concepts

  • HTTP interface to control the node
  • Use Websockets to communicate with other nodes (P2P)
  • Super simple “protocols” in P2P communication
  • Data is not persisted in nodes
  • No proof-of-work or proof-of-stake: a block can be added to the blockchain without competition

alt tag

alt tag


For a more extensive tutorial about blockchains, you can check the project Naivecoin. It is based on Naivechain and implements for instance Proof-of-work, transactions and wallets.

Quick start

(set up two connected nodes and mine 1 block)

npm install
HTTP_PORT=3001 P2P_PORT=6001 npm start
HTTP_PORT=3002 P2P_PORT=6002 PEERS=ws://localhost:6001 npm start
curl -H "Content-type:application/json" --data '{ "data": "Some data to the first block" }' http://localhost:3001/mineBlock


Get blockchain
curl http://localhost:3001/blocks
Create block
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
Add peer
curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6001"}' http://localhost:3001/addPeer

Query connected peers

curl http://localhost:3001/peers