Skip to content

PHP blockchain: PoS consensus, EVM-compatible smart contracts, advanced synchronization (Fast/Light/Checkpoint), secp256k1 cryptography, mobile-optimized with 10x sync speed improvement.

License

Notifications You must be signed in to change notification settings

RandomCoderTinker/phpblockchain-forked

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ PHP Blockchain Platform

PHP Version License Version

A professional blockchain platform built with PHP 8+, featuring Proof of Stake consensus, smart contracts, advanced synchronization systems, and enterprise security.

✨ Key Features

πŸ”— Core Blockchain

  • Proof of Stake Consensus - Energy-efficient consensus mechanism
  • Smart Contracts - EVM-compatible virtual machine
  • Advanced Cryptography - secp256k1, ECDSA, Keccak-256
  • High Performance - 1000+ transactions per second

⚑ Advanced Synchronization

  • Fast Sync - 10x faster synchronization with state snapshots
  • Light Client - 92% storage reduction with SPV verification
  • Checkpoint Sync - Instant bootstrapping from trusted checkpoints
  • Mobile Optimized - Efficient sync for resource-constrained devices

πŸ›‘οΈ Enterprise Security

  • Hardware Security Module - Professional key management
  • Multi-signature Support - Enhanced transaction security
  • Rate Limiting - DDoS protection
  • Secure Storage - AES-256 encryption

πŸ”§ Developer Tools

  • RESTful API - Complete blockchain interaction API
  • CLI Tools - Command-line interface for operations
  • Web Explorer - Built-in blockchain explorer
  • Comprehensive Tests - Full test coverage

πŸš€ Quick Start

Requirements

System Requirements

  • PHP 8.0 or higher with the following extensions:
    • OpenSSL (for cryptographic operations)
    • cURL (for network communications)
    • JSON (for data serialization)
    • mbstring (for string manipulation)
    • MySQLi or PDO (for database operations)
  • Composer (dependency management)
  • MySQL 8.0+ or MariaDB 10.4+ (optional, for persistent storage)
  • Redis (optional, for caching and session storage)

Development Requirements

  • Git (for version control)
  • Docker & Docker Compose (optional, for containerized deployment)
  • Node.js 16+ (optional, for frontend tools)

Production Requirements

  • Web server (Apache/Nginx)
  • SSL certificate (for HTTPS)
  • Firewall configuration (ports 8545, 8546)
  • Backup solution (for blockchain data)

Installation

# Clone the repository
git clone https://github.com/infosave2007/phpblockchain.git
cd phpblockchain

# Install dependencies (simplified - works without database extensions)
composer install --ignore-platform-req=ext-mysqli --ignore-platform-req=ext-pdo_mysql --ignore-platform-req=ext-gmp --no-dev

# Alternative: Install with development tools
# composer install --ignore-platform-req=ext-mysqli --ignore-platform-req=ext-pdo_mysql --ignore-platform-req=ext-gmp

# Copy environment configuration
cp .env.example config/.env

# Set proper permissions
chmod +x server.php cli.php crypto-cli.php check.php
chmod -R 755 storage/ logs/

# Create required directories
mkdir -p storage/blocks storage/state storage/cache
mkdir -p logs/blockchain logs/transactions

# Run system check
php check.php

# Initialize configuration (optional - use web installer instead)
php cli.php init --network="My Network" --symbol="MBC"

Configuration

Environment Variables (config/.env)

# Blockchain Configuration
BLOCKCHAIN_NETWORK=mainnet
BLOCKCHAIN_SYMBOL=MBC
CONSENSUS_ALGORITHM=pos
BLOCK_TIME=10
INITIAL_SUPPLY=1000000

# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=blockchain
DB_USERNAME=blockchain_user
DB_PASSWORD=your_secure_password

# Network Configuration
MAX_PEERS=25

# Security
API_KEY=your_secure_api_key_32_chars_min
ADMIN_EMAIL=admin@yourdomain.com
RATE_LIMIT_ENABLED=true

Web-based Installation

Open browser and navigate to:

http://localhost:xxxx/web-installer/ wallet_step1 wallet_step2 wallet_step3 wallet_step4 wallet_step5 wallet_step6 wallet_step7

Follow the installation wizard


#### Manual Database Setup
```sql
CREATE DATABASE blockchain;
CREATE USER 'blockchain_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON blockchain.* TO 'blockchain_user'@'localhost';
FLUSH PRIVILEGES;

Quick Verification

# Run tests
php test.php

# Start the demo
php demo.php

# Professional unit tests
./vendor/bin/phpunit

# Check system status
php cli.php status

Basic Usage

<?php
require_once 'vendor/autoload.php';

use Blockchain\Core\Cryptography\KeyPair;
use Blockchain\Core\Transaction\Transaction;
use Blockchain\Core\Blockchain\Block;

// Generate keypairs
$alice = KeyPair::generate();
$bob = KeyPair::generate();

// Create transaction
$transaction = new Transaction(
    $alice->getPublicKey(),
    $bob->getPublicKey(),
    100.0,
    0.1
);

// Create block
$block = new Block(1, [$transaction], 'previous_hash', time());

echo "Block hash: " . $block->getHash() . "\n";

πŸ“Š Performance Benchmarks

Feature Performance
Transaction Processing 1,000+ tx/sec
Block Validation 10+ blocks/sec
Sync Speed (Fast) 10x improvement
Storage (Light Client) 92% reduction
Memory Usage < 10MB

πŸ—οΈ Architecture

β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ Blockchain/         # Blockchain core logic
β”‚   β”œβ”€β”€ Cryptography/       # Cryptographic functions
β”‚   β”œβ”€β”€ Consensus/          # Proof of Stake implementation
β”‚   β”œβ”€β”€ Transaction/        # Transaction processing
β”‚   β”œβ”€β”€ SmartContract/      # Smart contract VM
β”‚   β”œβ”€β”€ Sync/              # Advanced synchronization
β”‚   └── Security/          # Security features
β”œβ”€β”€ api/                   # REST API
β”œβ”€β”€ wallet/                # Wallet management
β”œβ”€β”€ tests/                 # Test suite
└── examples/              # Usage examples

πŸ” Security Features

  • secp256k1 Elliptic Curve Cryptography
  • ECDSA Digital Signatures
  • Keccak-256 Cryptographic Hashing
  • Secure Key Generation and Storage
  • Multi-signature Transaction Support
  • Hardware Security Module Integration

⚑ Synchronization Strategies

Fast Sync

  • Downloads state snapshots
  • 10x faster than full sync
  • Validates recent blocks only

Light Client

  • Downloads block headers only
  • SPV verification with Merkle proofs
  • 92% storage reduction

Checkpoint Sync

  • Bootstraps from trusted checkpoints
  • Instant network joining
  • Suitable for new nodes

πŸ§ͺ Testing

# Run all tests
./vendor/bin/phpunit

# Run simple tests
php test.php

# Run performance demo
php demo.php

πŸ”§ Troubleshooting

Common Issues

Permission Errors

# Fix file permissions
chmod -R 755 storage/ logs/
chown -R www-data:www-data storage/ logs/  # Linux/Ubuntu
chown -R _www:_www storage/ logs/          # macOS

OpenSSL Extension Missing

# Ubuntu/Debian
sudo apt-get install php-openssl

# CentOS/RHEL
sudo yum install php-openssl

# macOS
brew install openssl

Missing Database Extensions

# Ubuntu/Debian
sudo apt-get install php-mysqli php-pdo-mysql php-gmp

# CentOS/RHEL
sudo yum install php-mysqli php-pdo php-gmp

# macOS
brew install php-gmp

# Alternative: Install without database extensions
composer install --ignore-platform-req=ext-mysqli --ignore-platform-req=ext-pdo_mysql --ignore-platform-req=ext-gmp

Composer Issues

# Update Composer
composer self-update

# Clear cache
composer clear-cache

# Install with increased memory
php -d memory_limit=2G composer install

Database Connection Issues

# Test database connection
php cli.php db:test

# Create database manually
mysql -u root -p -e "CREATE DATABASE blockchain;"

GitHub Authentication Issues

# If you get GitHub authentication errors during installation
composer clear-cache
rm -rf vendor/ composer.lock

# Use the simplified installation
composer install --ignore-platform-req=ext-mysqli --ignore-platform-req=ext-pdo_mysql --ignore-platform-req=ext-gmp --no-dev

πŸ“š API Documentation

Create Transaction

POST /api/transaction
{
    "from": "public_key",
    "to": "public_key", 
    "amount": 100.0,
    "fee": 0.1
}

Get Block

GET /api/block/{hash}

Get Balance

GET /api/balance/{address}

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸš€ Deployment

Docker

docker-compose up -d

Traditional Server

# Configure web server to point to index.php
# Set proper permissions
chmod +x server.php
php server.php

πŸ“ˆ Roadmap

  • Layer 2 scaling solutions
  • Cross-chain interoperability
  • Advanced governance features
  • Mobile wallet applications
  • Enterprise integration tools

πŸ’¬ Support


Built with ❀️ using PHP 8+ and modern blockchain technologies

About

PHP blockchain: PoS consensus, EVM-compatible smart contracts, advanced synchronization (Fast/Light/Checkpoint), secp256k1 cryptography, mobile-optimized with 10x sync speed improvement.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 90.6%
  • JavaScript 6.3%
  • HTML 1.5%
  • CSS 1.5%
  • Dockerfile 0.1%