Table of Contents
A blockchain written in python which outputs and reads chain data from a json file.
The code was adapted from the following tutorial and expanded upon.
https://hackernoon.com/learn-blockchains-by-building-one-117428612f46
Here's why:
- To expand my coding abilities and tackle new novel problems
- For fun and to learn how blockchains work by creating my own
- Something to do in my off time
I hope to make this project the best it can be, and I hope others find it interesting or may wish to contribute. I'm not a professional developer or expert so the code may not be 100% efficient, But I do welcome contributions to the project.
Be sure to read this readme in full before trying to get set up or submitting any issues to the repo.
Install the requirements with
- pip
pip install -r requirements.txt
- Clone the repo
git clone https://github.com/ock666/serpentcoin.git
- Install the requirements
pip install -r requirements.txt
- You may need to install Tkinter as a dependency for PySimpleGUI
apt install python3-tk
- If you receive an error stating python cannot import Image, you may also need to install Pillow as a dependency for qrcode.
pip3 -U install Pillow
- Run blockchain.py to generate chain.json and wallet.json.
python3 blockchain.py
- Start blockchain.py node, (and provide it a port number to run on) to generate wallet.json, and chain.json.
python3 blockchain.py
- If a node already exists, upon start up you can connect to nodes configured in the data/config.json file to receive the chain and mempool from upstream.
- To begin mining, start miner.py and enter the IP address of a node.
python3 miner.py
- Miners will now attempt to forge new blocks.
- Congrats! the blockchain network is now set up!
- Upon miners receiving rewards, wallet.py can be used to send coins to other addresses on the network.
- any transactions sent from the wallet.py or pool.py will confirm in the next block.
The blockchain can be interacted with using either Postman or simple cURL commands to send POST/GET requests to the API to either:
1. Request the blockchain history /chain \\ GET
2. Register a new node /nodes/register // POST
This is the main blockchain node that everything will connect to, including other blockchain.py nodes, as well as pool.py, and wallet.py. The blockchain will verify funds, hashes, and signatures and forge blocks with new transactions waiting to be confirmed in the mem-pool when a miner or pool finds the correct proof for the next block.
The blockchain now has the capability to share newly mined block with other nodes, receiving nodes will perform validation on the new block to confirm the proof
Nodes will verify the public key hex and the signature to verify a transaction. if the signature verification fails, the transaction is denied.
Nodes will check the balance of an address from the blockchain, if a sender has insufficient balance. The transaction will be denied.
The blockchain will check the hashes of any broadcasted transactions or blocks to ensure authenticity in transmission.
Upon receiving and verifying a new transaction nodes will broadcast the transaction to other nodes, receiving nodes will check if the transaction is already in their mem-pool, perform their own validation; and either accept or deny the transaction.
Every 10 blocks the blockchain will either scale mining difficulty up or down to attempt to reach an epoch time of 5 minutes.
This is the miner for the blockchain that will attempt to forge new blocks by solving proofs that output to a defined hash structure; which will solve for the next block. The miner has two modes, solo and pool.
This is the GUI wallet for ease of sending transactions to the blockchain. Simply input the address of the recipient, the amount to send, and hit OK. If you have enough funds, and dont have an existing transaction in the mem-pool; your transaction will be broadcasted to the network and confirmed in the next block.
a simple GUI to send transactions to the blockchain node without having to interact with a terminal.
When The wallet starts it will ask you to enter the address of a node:
After the wallet has successfully connected to a blockchain node it will display the following. From this interface a user may send transactions or view their transaction history.
view your transaction history within the wallet
- Add chain persistence through json
- Add block and transaction broadcasting
- Add signature and hash validation
- Add Balance Verification
- Develop Wallet
- Improved difficulty algorithm; doesnt scale so aggressively anymore.
- Add pool mining - Removed as of Alpha 0.0.1, will be readded upon improvement
- Improve pool mining efficiency
- Implement mining difficulty scaling to ensure consistent block times
- Node persistence - WIP
- implement code to allow for nodes to remember each other after they have been shut down
- implement a validation algorithm through signatures to ensure a node is who they say they are
- Improve overall code robustness - WIP
- Fix up some of the response codes and json messages
- code clean up, bug fixes, and optimisation
- unit test more of the code
- Transaction Fees - WIP
- Implement blockchain explorer (WIP) Explorer
- develop method to call chain API from a node and enter the values into a database
- develop backend to process chain data from database and analyse it
- develop frontend for a user to check address and transactions within blocks
- develop basic mobile wallet app
- create method to generate QR codes from addresses
- allow the app to scan an address from qr code and plug that address into a new transaction window
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this project better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Your Name - Oskar Petersen - [email protected]
Project Link: https://github.com/ock666/serpentcoin