This project implements a simple blockchain and a basic API using Flask. The blockchain supports basic functionalities such as mining new blocks, adding transactions, and resolving conflicts between nodes.
-
Clone the repository:
git clone https://github.com/prathik2401/blockchain-in-python.git cd blockchain-in-python -
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install the dependencies:
pip install -r requirements.txt
-
Start the Flask server:
python blockchain.py
-
Access the API: Open your web browser and go to
http://127.0.0.1:5000.
-
Mine a new block:
- URL:
/mine - Method:
GET - Description: Mines a new block and adds it to the blockchain.
- URL:
-
Create a new transaction:
- URL:
/transactions/new - Method:
POST - Description: Adds a new transaction to the list of transactions.
- Payload:
{ "sender": "address_of_sender", "recipient": "address_of_recipient", "amount": 10 }
- URL:
-
Get the full blockchain:
- URL:
/chain - Method:
GET - Description: Returns the full blockchain.
- URL:
-
Register new nodes:
- URL:
/nodes/register - Method:
POST - Description: Registers new nodes in the network.
- Payload:
{ "nodes": ["http://127.0.0.1:5001"] }
- URL:
-
Resolve conflicts:
- URL:
/nodes/resolve - Method:
GET - Description: Resolves conflicts between nodes by replacing the chain with the longest one in the network.
- URL:
To test the application, you can use tools like curl or Postman to interact with the API endpoints.
This project is licensed under the MIT License. See the LICENSE file for details.