This project is created to learn blockchain by creating a small blockchain and it's own coin.
To find the latest version please go to the VERSION
file present at project's base directory
- Python >= 3.6
If you are running other python versions, this project can be ported to other python versions with small syntax changes.
- Pull the docker image:
sudo docker pull prakashpandey/tinycoin:1.6
- Run the docker image:
sudo docker run -p 5000:5000 -d prakashpandey/tinycoin:1.6
That's it. You have successfully installed the tinycoin
docker image.
Note: Instead of version 1.6
you can also use version latest
but it may not be stable one.
To find the latest version please go to the VERSION
file present at project's base directory
-
git clone https://github.com/prakashpandey/tinycoin
-
cd tinycoin
-
pip3 install -r requirements.txt
orpip install -r requirements.txt
based on yourpip
version
./start.sh
Note: If your environment uses python
instead of python3
then edit the start.sh
script.
-
set
HOST
,PORT
,PEERS
andMINER_ADDRESS
environment variables. FollowConfiguration
section for more details. -
python src/app.py
By default the application will run on port 5000
Open file start.sh
.
You can set the values of following environment variables according to your needs.
-
HOST="http://127.0.0.1"
-
PORT=5000
-
PEERS="http://192.168.1.11:5000,http://192.168.1.12:5000"
-
MINER_ADDRESS="ppdpp-dvfgf-fredgdsdf-gdsfgsd-35vr433-ee2eass4d"
If you are intrested in building your own docker image please read this section otherwise you can skip this.
-
clone project:
git clone https://github.com/prakashpandey/tinycoin
-
cd tinycoin
-
build docker image:
sudo docker build -t username/repo-name:tag .
-
List all docker images:
sudo docker image ls
-
List all docker containers:
sudo docker container ls
Blockchain is all about distribute network where one connect with different peers
and exchange data on regular bases.
During developement, you will probabily not have a group of distributed peers with whome you may want to connect and exchange
data.
To solve this problem, testing.sh
script will help you run multiple blockchain instance on different ports
on the same machine. Open the file testing.sh
and edit it according to your needs.
-
Method = Get
-
Url = localhost:5000/get_miner_address
-
API response
Returns miner address
Method = Post
Url = 127.0.0.1:5000/update_miner_address
- Body
{ "miner_address": "ppdpp-dvfgf-fredgdsdf-gdsfgsd-35vr433-ee2eass4d" }
- Headers:
Content-Type=application/json
- API response
Successfully updated miner address
orCan not update miner_address as valid miner address is not found
Append peers to existing peer list
Method = Post
Url = 127.0.0.1:5000/append_peers
- Body
[ "http://192.168.1.11:5000", "http://192.168.1.12:5000" ]
- Headers:
Content-Type=application/json
- API response
Peer list updated
orFailed while adding peer/peers. Error[empty peer list received]
Override the existing peers list with new given peers
list.
Method = Post
Url = 127.0.0.1:5000/add_peers
- Body
[ "http://192.168.1.11:5000", "http://192.168.1.12:5000" ]
- Headers:
Content-Type=application/json
- API response
Peer list updated
orFailed while adding peer/peers. Error[empty peer list received]
Method = Post
Url = 127.0.0.1:5000/transaction
- Body
{ "from": "71238uqirbfh894-random-public-key-a-alkjdflakjfewn204ij", "to": "ppdpp-dvfgf-fredgdsdf-gdsfgsd-35vr433-ee2eass4d", "amount": 2 }
- Headers:
Content-Type=application/json
- API response
Transaction submission successful
orTransaction unsuccessful
-
Method = Get
-
Url = localhost:5000/mine
-
API response
Mined block in JSON format
-
Method = Get
-
Url = localhost:5000/blocks
-
API response
Blockchain in JSON format
-
Method = Get
-
Url = localhost:5000/consensus
-
API response
Consensus successfully done
-
Method = Get
-
Url = localhost:5000/peers
-
API response
["http://127.0.0.1:5001", "http://127.0.0.1:5002"]
-
Method = Get
-
Url = localhost:5000/connect_to_peers_of_peers
-
API response
["http://127.0.0.1:5002", "http://127.0.0.1:5000"]
The only aim creating this project is to learn and explore about blockchain. Currently the consensus and proof of work algorithms are very simple. There is scope of improving these algorithm.
-
A wallet client
-
Update proof of work and consensus algorithm
-
A valid miner address validater
This learning project is created just for learning and based on open blog articles on internet.
GPL V3, please visit LICENSE for more information.