This project is a fully functioning Proof-of-Work (PoW) blockchain written in Python, complete with mining, transaction validation, and wallet creation. The blockchain is integrated with a FastAPI backend to provide a user-friendly API and a simple HTML interface to interact with the blockchain.
- Proof-of-Work (PoW): Ensures security and decentralization by requiring computational work to mine new blocks.
- Mining Rewards: Miners receive a fixed reward for successfully mining a new block.
- Wallets & Transactions: Generate wallets with public/private keys and send/receive transactions between addresses.
- Blockchain Validation: Ensures the integrity of the entire chain by validating hashes and transactions.
- API Integration: Use FastAPI to interact with the blockchain via RESTful endpoints.
- Static HTML Interface: Simple web interface for basic blockchain interactions.
Blockchain-Project
├── .venv/ # Virtual environment
├── src/ # Source code folder
│ ├── static/ # Static HTML files for the web interface
│ ├── blockchain.py # Core blockchain logic
│ ├── node.py # FastAPI server for the blockchain
│ ├── wallet.py # Wallet generation and signature verification
│ ├── transaction.py# Transaction-related functions
│ ├── miner.py # Mining functionality
│ └── utils.py # Utility functions (e.g., hashing)
├── README.md # Project documentation
├── LICENSE # License file
└── requirements.txt # Dependencies
- Blockchain: The blockchain consists of a list of blocks, each containing transactions, a timestamp, a nonce, and a hash of the previous block.
- Proof-of-Work: Each block requires solving a computational puzzle (finding the correct nonce) before it can be added to the chain.
- Transactions: Users can create transactions by specifying a sender, receiver, and amount. These transactions are added to a pool of unconfirmed transactions.
- Mining: Miners take the pool of unconfirmed transactions and attempt to solve the PoW puzzle. Once solved, the block is added to the chain, and the miner receives a reward.
Method | Endpoint | Description |
---|---|---|
GET | /chain |
Get the entire blockchain |
GET | /wallet |
Create a new wallet |
GET | /balance/{address} |
Check balance of a wallet |
POST | /transaction |
Create a new transaction |
GET | /mine/{miner} |
Mine a new block |
GET | /validate |
Check if the blockchain is valid |
The project includes a static HTML interface to simplify interaction with the blockchain. The interface allows users to:
- View the current blockchain
- Create new wallets
- Send transactions
- Mine new blocks
- Check wallet balances
Before accessing the interface, ensure you have the necessary permissions and context for interacting with the project. If permissions are in place, you can access the interface by running the project and navigating to:
http://127.0.0.1:8080/static/index.html
Dependencies used in this project:
- FastAPI: For building the RESTful API
- cryptography: For generating and verifying digital signatures
- uvicorn: For running the FastAPI server
Once the project is deployed and running, you can interact with the blockchain using either the provided API endpoints or the HTML interface.
Use the following endpoints to interact with the blockchain:
- Create Wallet:
POST /wallet
- Check Balance:
GET /balance/{address}
- Send Transaction:
POST /transaction
- Mine Block:
GET /mine/{miner_address}
- Validate Blockchain:
GET /validate
Example using curl
to check balance:
curl -X GET http://127.0.0.1:8080/balance/YOUR_WALLET_ADDRESS
Navigate to the static HTML interface to easily interact with the blockchain:
http://127.0.0.1:8080/static/index.html
The interface allows you to view the blockchain, create wallets, send transactions, mine blocks, and check balances without needing to use the command line.
- Digital Signatures: Transactions are signed using the sender's private key to ensure authenticity and prevent tampering.
- Hashing: Each block contains the hash of the previous block, making it tamper-proof.
- Proof-of-Work: Adds security by requiring computational effort to add new blocks.
A wallet is created using a pair of public and private keys. The public key acts as the wallet address, while the private key is used to sign transactions.
Transactions include a sender, receiver, and amount. They are signed by the sender's private key and verified by the network before being added to the blockchain.
Miners collect unconfirmed transactions, solve a Proof-of-Work puzzle, and add a new block to the chain. The miner receives a reward for their work.
The blockchain can be validated by checking the hashes of each block and ensuring that all transactions are properly signed and verified.
- GPU Miner: Implement GPU-based mining to significantly increase mining efficiency and reduce computation time.
- Perceptron Integration: Integrate a perceptron-based AI model to optimize transaction validation, predict block hashes, and enhance security.
- Mobile Interface: Develop a mobile-friendly interface for interacting with the blockchain on the go.
- Smart Contracts: Add functionality for creating and executing smart contracts directly on the blockchain.
- Decentralized Nodes: Allow multiple nodes to run simultaneously, creating a decentralized blockchain network.
Copyright © 2025 Marc. All rights reserved.
Unauthorized use, reproduction, or distribution of this code is strictly prohibited.