Skip to content

Krishna2918/rustchain-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RustChain Python SDK

Python 3.8+ License: MIT

A clean, pip-installable Python SDK for interacting with the RustChain Proof-of-Antiquity blockchain network.

RustChain rewards real vintage hardware (PowerPC G4/G5, 68K Macs, SPARC, etc.) with higher mining multipliers than modern machines.

πŸš€ Installation

# From GitHub
pip install git+https://github.com/krishnadogra/rustchain-sdk.git

# Or clone and install locally
git clone https://github.com/krishnadogra/rustchain-sdk.git
cd rustchain-sdk
pip install -e .

πŸ“– Quick Start

Basic Usage

from rustchain import RustChainClient

# Connect to RustChain node
client = RustChainClient("https://50.28.86.131")

# Check node health
health = client.health()
print(f"Node status: {health.status}")

# Get all active miners
miners = client.get_miners()
for miner in miners:
    print(f"{miner.miner_id}: {miner.hardware_type} (x{miner.multiplier})")

# Check wallet balance
balance = client.get_balance("your-wallet-id")
print(f"Balance: {balance.balance} RTC")

# Get current epoch
epoch = client.get_epoch()
print(f"Current epoch: {epoch.epoch}")

# Check lottery eligibility
eligibility = client.check_eligibility("your-wallet-id")
if eligibility.eligible:
    print("You're eligible for the lottery! πŸŽ‰")

# Clean up
client.close()

Context Manager (Recommended)

from rustchain import RustChainClient

with RustChainClient("https://50.28.86.131") as client:
    miners = client.get_miners()
    print(f"Active miners: {len(miners)}")

Async Usage

import asyncio
from rustchain import AsyncRustChainClient

async def main():
    async with AsyncRustChainClient("https://50.28.86.131") as client:
        # All methods are async
        health = await client.health()
        miners = await client.get_miners()
        
        # Concurrent requests
        balance, epoch = await asyncio.gather(
            client.get_balance("wallet-1"),
            client.get_epoch()
        )
        
        print(f"Balance: {balance.balance} RTC")
        print(f"Epoch: {epoch.epoch}")

asyncio.run(main())

Transfer Tokens

from rustchain import RustChainClient

with RustChainClient("https://50.28.86.131") as client:
    result = client.transfer(
        from_wallet="your-wallet",
        to_wallet="recipient-wallet",
        amount=10.0,
        private_key="your-private-key"
    )
    
    if result.success:
        print(f"Transfer complete! TX: {result.tx_hash}")
    else:
        print(f"Transfer failed: {result.message}")

Submit Attestation

from rustchain import RustChainClient

with RustChainClient("https://50.28.86.131") as client:
    result = client.submit_attestation({
        "miner_id": "your-miner-id",
        "hardware_proof": "...",
        "timestamp": "2026-02-02T19:00:00Z"
    })
    
    if result.success:
        print(f"Attestation ID: {result.attestation_id}")

πŸ–₯️ CLI Usage

The SDK includes a command-line interface:

# Check node health
rustchain-cli health

# List all miners
rustchain-cli miners

# Get wallet balance
rustchain-cli balance your-wallet-id

# Get current epoch
rustchain-cli epoch

# Check lottery eligibility
rustchain-cli eligibility your-wallet-id

# Use different node
rustchain-cli --node https://other-node.com miners

# JSON output
rustchain-cli --json miners

βš™οΈ Configuration

Client Options

client = RustChainClient(
    base_url="https://50.28.86.131",
    verify_ssl=False,      # Disable SSL verification (self-signed certs)
    timeout=30.0,          # Request timeout in seconds
    max_retries=3,         # Number of retry attempts
    retry_delay=1.0,       # Initial retry delay (exponential backoff)
)

SSL Certificates

The default RustChain node uses a self-signed certificate. SSL verification is disabled by default. To enable:

client = RustChainClient("https://node.com", verify_ssl=True)

πŸ“Š API Reference

RustChainClient

Method Description Returns
health() Get node health status HealthStatus
get_miners() List all active miners List[Miner]
get_balance(miner_id) Get wallet balance WalletBalance
get_epoch() Get current epoch info EpochInfo
check_eligibility(miner_id) Check lottery eligibility EligibilityStatus
submit_attestation(payload) Submit attestation AttestationResult
transfer(from, to, amount, key) Transfer tokens TransferResult

Data Models

  • HealthStatus: status, version, uptime
  • Miner: miner_id, hardware_type, multiplier, blocks_mined, balance
  • WalletBalance: miner_id, balance, pending
  • EpochInfo: epoch, started_at, ends_at, block_height
  • EligibilityStatus: miner_id, eligible, reason
  • AttestationResult: success, attestation_id, message
  • TransferResult: success, tx_hash, message

πŸ§ͺ Testing

# Install dev dependencies
pip install -e ".[dev]"

# Run unit tests
pytest tests/ -v

# Run integration tests (requires live node)
pytest tests/ -v -m integration

# Run all tests with coverage
pytest tests/ -v --cov=rustchain

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

πŸ“œ License

MIT License - see LICENSE for details.

πŸ”— Links


Built with ❀️ for the RustChain community

About

Python SDK for RustChain Proof-of-Antiquity blockchain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages