https://github.com/koshikraj/pynaivechain
Python implementation of naivechain project
https://github.com/koshikraj/pynaivechain
blockchain python sanic websocket
Last synced: 4 months ago
JSON representation
Python implementation of naivechain project
- Host: GitHub
- URL: https://github.com/koshikraj/pynaivechain
- Owner: koshikraj
- License: apache-2.0
- Created: 2018-03-06T03:28:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-24T06:42:14.000Z (over 7 years ago)
- Last Synced: 2025-04-02T20:06:08.858Z (7 months ago)
- Topics: blockchain, python, sanic, websocket
- Language: Python
- Size: 69.3 KB
- Stars: 18
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pynaivechain
Python implementation of [naivechain](https://github.com/lhartikk/naivechain) project[](https://travis-ci.org/koshikraj/pynaivechain)
# Naivechain - a blockchain implementation in 200 lines of code
### 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](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.### Key concepts of Naivechain
Check 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
* 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

### Naivecoin
For 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.### Quick start
(set up two connected nodes and mine 1 block)
```
install python version >= 3.5pip 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
```### Quick start with Docker
(set up three connected nodes and mine a block)
###
```sh
docker-compose up
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
```### HTTP API
##### 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
```