This is a Python implementation of a Proof-of-Stake (PoS) blockchain with a P2P network, REST API, and Vue.js explorer. The project demonstrates core blockchain concepts including:
- Block creation and validation
- Proof-of-Stake consensus algorithm
- Transaction handling and wallets
- P2P networking between nodes
- REST API for blockchain interaction
- Web-based blockchain explorer
- Docker and Docker Compose
- Node.js and Yarn (for the explorer)
docker-compose up --buildThis will start 4 validator nodes with the following configuration:
-
validator_alpha (Genesis node)
- Node Port: 9010
- API Port: 9050
-
validator_beta
- Node Port: 9011
- API Port: 9051
-
validator_gamma
- Node Port: 9012
- API Port: 9052
-
validator_delta
- Node Port: 9013
- API Port: 9053
In a new terminal, navigate to the explorer directory and start the Vue.js application:
cd frontend
yarn install
yarn startThe explorer will be available at http://localhost:8080
In a new terminal, you can generate sample transactions to test the blockchain:
python sample_transactions.pyThis script will create various types of transactions (EXCHANGE, STAKE, TRANSFER) and post them to the first node's API.
pos-blockchain/
├── blockchain/ # Core blockchain implementation
├── api/ # FastAPI REST API
├── frontend/ # Vue.js blockchain explorer
├── keys/ # Key generation and storage
├── Dockerfile # Docker image definition
├── docker-compose.yml # Multi-node Docker setup
├── requirements.txt # Python dependencies
├── run_node.py # Single node runner
├── run_n_nodes.py # Multi-node runner
└── sample_transactions.py # Sample transaction generator
Each node exposes a REST API with the following endpoints:
GET /api/v1/blockchain/- Get the entire blockchainGET /api/v1/blockchain/block/{block_height}- Get a specific blockGET /api/v1/blockchain/peers/- Get connected peers
GET /api/v1/transaction/transaction_pool/- Get transactions in mempoolPOST /api/v1/transaction/create/- Create a new transactionGET /api/v1/transaction/{transaction_hash}- Get a specific transactionGET /api/v1/transaction/{address}/transactions/- Get transactions for an addressGET /api/v1/transaction/{address}/balance/- Get balance for an address
GET /ping/- Basic health check
To stop the blockchain network:
docker-compose down