This project implements a basic blockchain and transaction system using FastAPI for the API endpoints. The blockchain supports adding blocks and transactions, and propagates them to known nodes in the network.
- Blockchain: A simple blockchain implementation with genesis block creation, block addition, and chain validation.
- Transactions: Support for creating and adding transactions.
- API Endpoints: FastAPI endpoints for adding transactions and blocks.
- Threaded Propagation: Transactions and blocks are propagated to known nodes in separate threads.
- Ascon Hashing: Utilizes Ascon hash for lightweight and efficient hashing.
-
Clone the repository:
git clone https://github.com/your-repo/blockchain-project.git cd blockchain-project
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the FastAPI server:
python Node.py
-
Interact with the API:
- Add a transaction:
curl -X POST "http://localhost:8000/transaction" -H "Content-Type: application/json" -d '{"data": "some data", "from_account": "account1", "sign": "signature"}'
- Add a block:
curl -X POST "http://localhost:8000/block" -H "Content-Type: application/json" -d '{"data": "some data", "prev_hash": "previous hash", "sign": "signature"}'
- Add a transaction:
Node.py
: Main file to run the FastAPI server and handle API endpoints.Blockchain.py
: Contains theBlockchain
class and related methods.Client.py
: Contains theClient
class for creating and sending transactions.Transaction.py
: Defines theTransaction
class.Block.py
: Defines theBlock
class.configs.py
: Configuration file for server settings and initial known nodes.requirements.txt
: List of dependencies.