Skip to content

naiveprime - a blockchain based on naivechain implementation by lhartikk and prime calculation as proof-of-work

License

Notifications You must be signed in to change notification settings

heryxpc/naivechainprime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Naivechainprime - Code based on: https://github.com/lhartikk/naivechain - a blockchain implementation in 200 lines of code.

Main difference is that this case uses prime numbers to validate new blocks.

Modified to support an example of Proof of Work: calculate prime numbers and hash them.

Motivation

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 Naiveprime

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
  • Proof-of-work based on prime numbers calculation

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" : {"id" : "miner_id", "prime": "30697F786F60CA6EAC8964C5B5D21CCBA0A60DCEE0549485F7F6748FF7DBBCC0" }}' https://localhost:3001/mineBlock

HTTP API

Get blockchain
curl http://localhost:3001/blocks
Create block
curl -H "Content-type:application/json" --data '{"id" : "miner_id", "prime": "hashed_prime" }' 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

About

naiveprime - a blockchain based on naivechain implementation by lhartikk and prime calculation as proof-of-work

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%