An open API service indexing awesome lists of open source software.

https://github.com/shadow-leaked/private-blockchain-in-python

This is a simple implementation of a private blockchain in Python that logs data entries (such as system logs) into blocks. Each block is linked via cryptographic hashes, and the blockchain is exposed via a simple Flask REST API.
https://github.com/shadow-leaked/private-blockchain-in-python

blockchain-technology python rest-api

Last synced: about 1 year ago
JSON representation

This is a simple implementation of a private blockchain in Python that logs data entries (such as system logs) into blocks. Each block is linked via cryptographic hashes, and the blockchain is exposed via a simple Flask REST API.

Awesome Lists containing this project

README

          

# Private Blockchain in Python

This is a simple implementation of a private blockchain in Python that logs data entries (such as system logs) into blocks. Each block is linked via cryptographic hashes, and the blockchain is exposed via a simple Flask REST API.

## Features

- **Block Creation:** Each block contains an index, timestamp, data, hash, nonce, and the previous block's hash.
- **Proof-of-Work:** A simple proof-of-work mechanism secures the blockchain.
- **REST API:** Use the `/mine` endpoint to add new blocks and the `/chain` endpoint to view the entire blockchain.
- **Easy Deployment:** Ideal for local or private projects, with clear instructions for running and extending the code.

## Getting Started

### Prerequisites

- [Python 3](https://www.python.org/downloads/)
- [pip](https://pip.pypa.io/en/stable/installation/)
- (Optional) [Git](https://git-scm.com/)

### Installation

1. **Clone the Repository:**
```bash
git clone https://github.com/shadow-leaked/Private-Blockchain-in-Python
cd Private-Blockchain-in-Python
```
2. **Create and Activate a Virtual Environment:**
```
python -m venv venv
# Activate the virtual environment:
# On Windows (PowerShell):
.\venv\Scripts\Activate.ps1
# On macOS/Linux:
source venv/bin/activate
```
3. **Install Dependencies:**
```
pip install -r requirements.txt
```
### Running the Server
Start the Flask server by running:
```
python server.py
```
The server will start on http://127.0.0.1:5000.

### Using the API
- **Mine a New Block:**

- **Send a POST request to /mine with JSON data. For example:**
```
curl.exe -X POST -H "Content-Type: application/json" -d "{\"data\": \"Log entry 1: System started.\"}" http://127.0.0.1:5000/mine
```
- **View the Blockchain:**

Open your browser or use a tool like curl to visit:
```
http://127.0.0.1:5000/chain
```
### Contributing
Contributions are welcome! Please fork the repository and submit pull requests.

### License
This project is licensed under the [MIT License](LICENSE).

### Acknowledgements
This project is a learning exercise in blockchain development.
Inspired by various open-source blockchain projects and tutorials.