This project demonstrates a basic blockchain implementation using Flask, where each block is represented as a class. The application provides three RESTful API endpoints to mine new blocks, retrieve the entire blockchain, and check the validity of the blockchain.
- Python 3.x
- Flask (install using
pip install Flask==0.12.2
)
-
Clone the repository:
git clone https://github.com/TUR14CUS/blockchain-flask.git cd blockchain-flask
-
Install Flask:
pip install Flask==0.12.2
python main.py
The application will be running at http://localhost:5000/
.
- Endpoint:
/mine_block
- Method: GET
- Description: Mine a new block and add it to the blockchain.
- Endpoint:
/get_chain
- Method: GET
- Description: Retrieve the entire blockchain.
- Endpoint:
/is_valid
- Method: GET
- Description: Check if the current blockchain is valid.
-
Mine a New Block:
- Endpoint:
http://localhost:5000/mine_block
- Method: GET
- Endpoint:
-
Get the Full Blockchain:
- Endpoint:
http://localhost:5000/get_chain
- Method: GET
- Endpoint:
-
Check Blockchain Validity:
- Endpoint:
http://localhost:5000/is_valid
- Method: GET
- Endpoint:
-
Success (200 OK):
{ "message": "All good. The Blockchain is valid." }
-
Success (201 Created):
{ "message": "Congratulations, you just mined a block!", "index": 2, "timestamp": "2024-01-30 12:00:00", "proof": 12345, "previous_hash": "previous_hash_value" }
-
Error (400 Bad Request):
{ "message": "Houston, we have a problem. The Blockchain is not valid." }
- main.py: Entry point of the application.
- blockchain.py: Contains the blockchain logic and Flask-RESTful resource classes.
- README.md: Project documentation.
Feel free to contribute to this blockchain implementation by opening issues or creating pull requests. Your feedback and suggestions are highly appreciated.
This project is licensed under the MIT License.