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.
- Host: GitHub
- URL: https://github.com/shadow-leaked/private-blockchain-in-python
- Owner: shadow-leaked
- License: mit
- Created: 2025-02-26T09:46:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-26T10:03:03.000Z (over 1 year ago)
- Last Synced: 2025-02-26T10:36:39.102Z (over 1 year ago)
- Topics: blockchain-technology, python, rest-api
- Language: Python
- Homepage: https://github.com/shadow-leaked/Private-Blockchain-in-Python
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
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.