ChainAlchemy is a blockchain application that provides a comprehensive system for creating and managing wallets, processing transactions, mining blocks, and achieving consensus between nodes. It offers a RESTful API built with Flask to facilitate interaction with the blockchain.
- Wallet creation with private and public key generation
- Transaction submission and validation
- Mining new blocks with proof of work
- Node registration and consensus mechanisms
- Full blockchain retrieval and validation
git clone https://github.com/hamdi3/ChainAlchemy.git
cd ChainAlchemy
You can install the necessary dependencies using pip
:
pip install -r requirements.txt
ChainAlchemy supports running the application via Docker for easy deployment and management. Follow the steps below to build and run the Docker container.
First, ensure that Docker is installed on your machine. Then, navigate to the project directory and run the following command to build the Docker image:
docker build -t chainalchemy:latest .
Once the image is built, you can run the application in a container using the following command:
docker run -d -p 5000:5000 --name chainalchemy_container chainalchemy:latest
- The
-d
flag runs the container in detached mode (in the background). - The
-p 5000:5000
option maps port 5000 on your host machine to port 5000 inside the container. --name chainalchemy_container
assigns a name to the running container.
Once the container is running, you can access the ChainAlchemy API at:
localhost:5000
To stop the running container, use the following command:
docker stop chainalchemy_container
To remove the container after stopping it, use the following command:
docker rm chainalchemy_container
Once everything is set up, you can run the Flask application:
python src/main.py
The API will now be available on http://localhost:5000
.
To explore the API documentation interactively, visit the Swagger UI on http://localhost:5000/swagger/
POST /wallet/new Generates a new wallet with a public/private key pair.
Response:
200 OK
: Wallet created successfully with public and private keys.
POST /transactions/new Submit a transaction from one wallet to another.
Required fields:
sender_address
: Sender's public addresssender_private_key
: Sender's private keyrecipient_address
: Recipient's public addressamount
: Transaction amount
Response:
201 Created
: Transaction will be added to the blockchain.400 Bad Request
: Missing required fields or insufficient balance.406 Not Acceptable
: Invalid transaction.
GET /transactions/get Retrieve a list of all transactions in the current pending pool.
Response:
200 OK
: Returns a list of pending transactions.
GET /chain Retrieve the entire blockchain.
Response:
200 OK
: Returns the blockchain and its length.
POST /mine Mine a new block and reward the miner.
Required fields:
miner_address
: The public address of the miner to receive rewards.
Response:
200 OK
: Block mined and added to the chain.400 Bad Request
: Missing required fields.
POST /nodes/register Register a new node for consensus.
Required fields:
nodes
: A non-empty list of node URLs.
Response:
201 Created
: Nodes successfully registered.400 Bad Request
: Invalid or missing node list.
GET /nodes/get Retrieve a list of all nodes in the network.
Response:
200 OK
: Returns a list of nodes.
GET /nodes/resolve Reach consensus across the nodes, resolving conflicts.
Response:
200 OK
: Returns the authoritative chain or indicates that the chain was replaced.
You can run the unit tests & generate coverage reports for this project using pytest
:
pytest --cov-report term --cov-report xml:tests/coverage.xml --cov=src/
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/