Python implementation of naivechain project
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.
From Wikipedia : Blockchain is a distributed database that maintains a continuously-growing list of records called blocks secured from tampering and revision.
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
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.
(set up two connected nodes and mine 1 block)
install python version >= 3.5
pip install -r requirements.txt
PORT=3001 python main.py
PORT=3002 PEERS=ws://localhost:3001 python main.py
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
(set up three connected nodes and mine a block)
docker-compose up
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
curl http://localhost:3001/blocks
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6001"}' http://localhost:3001/addPeer
curl http://localhost:3001/peers