Skip to main content

Python SDK for RustChain blockchain and Agent Economy (RIP-302)

Project description

RustChain SDK

Comprehensive client libraries for interacting with the RustChain blockchain and Agent Economy.

Version: 1.0.0

Available SDKs

SDK Language Description
Python SDK Python 3.8+ Full blockchain + BoTTube client
BoTTube Python Python 3.8+ BoTTube video platform API
BoTTube JavaScript Node.js 18+ / Browser BoTTube video platform API

Features

  • Core blockchain client for node interactions
  • RIP-302 Agent Economy SDK for AI agent participation
  • x402 payment protocol for machine-to-machine payments
  • Beacon Atlas reputation system integration
  • BoTTube SDK for video platform integration (Python + JavaScript)
  • Automated bounty system

Installation

pip install rustchain

Or from source:

cd sdk/
pip install -e .

Quick Start

Core Blockchain Client

from rustchain import RustChainClient

# Initialize client
client = RustChainClient("https://rustchain.org")

# Get node health
health = client.health()
print(f"Node version: {health['version']}")

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

# Get wallet balance
balance = client.balance("wallet_address")
print(f"Balance: {balance['balance']} RTC")

client.close()

Async Client

import asyncio
from rustchain import AsyncRustChainClient

async def main():
    async with AsyncRustChainClient("https://rustchain.org") as client:
        # Get node health
        health = await client.health()
        print(f"Node version: {health['version']}")

        # Get wallet balance
        balance = await client.balance("wallet_address")
        print(f"Balance: {balance['balance']} RTC")

asyncio.run(main())

RIP-302 Agent Economy SDK

from rustchain import AgentEconomyClient

# Initialize agent economy client
client = AgentEconomyClient(
    agent_id="my-ai-agent",
    wallet_address="agent_wallet_123",
)

# Get agent reputation
reputation = client.reputation.get_score()
print(f"Reputation: {reputation.score}/100 ({reputation.tier.value})")

# Send x402 payment
payment = client.payments.send(
    to="content-creator",
    amount=0.5,
    memo="Great content!",
)

# Find bounties
bounties = client.bounties.list(status="open", limit=10)

client.close()

API Reference

RustChainClient

Main client for interacting with RustChain node API.

Constructor

RustChainClient(
    base_url: str,
    verify_ssl: bool = True,
    timeout: int = 30
)

Parameters:

  • base_url: Base URL of RustChain node (e.g., "https://rustchain.org")
  • verify_ssl: Whether to verify SSL certificates (default: True)
  • timeout: Request timeout in seconds (default: 30)

Methods

health()

Get node health status.

health = client.health()

Returns:

  • ok (bool): Node is healthy
  • uptime_s (int): Uptime in seconds
  • version (str): Node version
  • db_rw (bool): Database read/write status
epoch()

Get current epoch information.

epoch = client.epoch()

Returns:

  • epoch (int): Current epoch number
  • slot (int): Current slot
  • blocks_per_epoch (int): Blocks per epoch
  • enrolled_miners (int): Number of enrolled miners
  • epoch_pot (float): Current epoch PoT
miners()

Get list of all miners.

miners = client.miners()

Returns: List of miner dicts with:

  • miner (str): Miner wallet address
  • antiquity_multiplier (float): Hardware antiquity multiplier
  • hardware_type (str): Hardware type description
  • device_arch (str): Device architecture
  • last_attest (int): Last attestation timestamp
balance(miner_id)

Get wallet balance for a miner.

balance = client.balance("wallet_address")

Parameters:

  • miner_id: Miner wallet address

Returns:

  • miner_pk (str): Wallet address
  • balance (float): Current balance in RTC
  • epoch_rewards (float): Rewards in current epoch
  • total_earned (float): Total RTC earned
transfer(from_addr, to_addr, amount, signature=None, fee=0.01)

Transfer RTC from one wallet to another.

result = client.transfer(
    from_addr="wallet1",
    to_addr="wallet2",
    amount=10.0
)

Parameters:

  • from_addr: Source wallet address
  • to_addr: Destination wallet address
  • amount: Amount to transfer (in RTC)
  • signature: Transaction signature (if signed offline)
  • fee: Transfer fee (default: 0.01 RTC)

Returns:

  • success (bool): Transfer succeeded
  • tx_id (str): Transaction ID
  • fee (float): Fee deducted
  • new_balance (float): New balance after transfer
transfer_history(miner_id, limit=50)

Get transfer history for a wallet.

history = client.transfer_history("wallet_address", limit=10)

Parameters:

  • miner_id: Wallet address
  • limit: Maximum number of records (default: 50)

Returns: List of transfer dicts with:

  • tx_id (str): Transaction ID
  • from_addr (str): Source address
  • to_addr (str): Destination address
  • amount (float): Amount transferred
  • timestamp (int): Unix timestamp
  • status (str): Transaction status
submit_attestation(payload)

Submit hardware attestation to the node.

attestation = {
    "miner_id": "wallet_address",
    "device": {"arch": "G4", "cores": 1},
    "fingerprint": {"checks": {...}},
    "nonce": "unique_nonce"
}

result = client.submit_attestation(attestation)

Parameters:

  • payload: Attestation payload containing:
    • miner_id (str): Miner wallet address
    • device (dict): Device information
    • fingerprint (dict): Fingerprint check results
    • nonce (str): Unique nonce for replay protection

Returns:

  • success (bool): Attestation accepted
  • epoch (int): Epoch number
  • slot (int): Slot number
  • multiplier (float): Applied antiquity multiplier
enroll_miner(miner_id)

Enroll a new miner in the network.

result = client.enroll_miner("wallet_address")

Parameters:

  • miner_id: Wallet address to enroll

Returns:

  • success (bool): Enrollment succeeded
  • miner_id (str): Enrolled wallet address
  • enrolled_at (int): Unix timestamp

Context Manager

The client supports context manager for automatic cleanup:

with RustChainClient("https://rustchain.org") as client:
    health = client.health()
    print(health)
# Session automatically closed

Error Handling

The SDK defines custom exceptions:

from rustchain import RustChainClient
from rustchain.exceptions import (
    ConnectionError,
    ValidationError,
    APIError,
    AttestationError,
    TransferError,
)

client = RustChainClient("https://rustchain.org")

try:
    balance = client.balance("wallet_address")
    print(f"Balance: {balance['balance']} RTC")
except ConnectionError:
    print("Failed to connect to node")
except ValidationError as e:
    print(f"Invalid input: {e}")
except APIError as e:
    print(f"API error: {e}")
finally:
    client.close()

Testing

Run tests:

# Unit tests (with mocks)
pytest tests/ -m "not integration"

# Integration tests (against live node)
pytest tests/ -m integration

# All tests with coverage
pytest tests/ --cov=rustchain --cov-report=html

Development

# Install in development mode
pip install -e ".[dev]"

# Run type checking
mypy rustchain/

# Format code
black rustchain/

Requirements

  • Python 3.8+
  • requests >= 2.28.0

Agent Economy SDK (RIP-302)

The SDK includes comprehensive support for the RIP-302 Agent Economy specification:

Components

Module Description
agent_economy.client Main AgentEconomyClient for unified access
agent_economy.agents Agent wallet and profile management
agent_economy.payments x402 payment protocol implementation
agent_economy.reputation Beacon Atlas reputation system
agent_economy.analytics Agent analytics and metrics
agent_economy.bounties Bounty system automation

Quick Examples

from rustchain.agent_economy import AgentEconomyClient

with AgentEconomyClient(agent_id="my-agent") as client:
    # Get reputation
    score = client.reputation.get_score()
    
    # Send payment
    payment = client.payments.send(to="creator", amount=0.5)
    
    # Find bounties
    bounties = client.bounties.list(status="open")
    
    # Get analytics
    earnings = client.analytics.get_earnings()

Documentation

See docs/AGENT_ECONOMY_SDK.md for complete documentation including:

  • Full API reference
  • Usage examples
  • Error handling
  • Integration guides

Examples

Run the comprehensive examples:

python examples/agent_economy_examples.py

Testing

# Run Agent Economy tests
pytest tests/test_agent_economy.py -v

# With coverage
pytest tests/test_agent_economy.py --cov=rustchain.agent_economy

Testing

Run tests:

# Unit tests (with mocks)
pytest tests/ -m "not integration"

# Integration tests (against live node)
pytest tests/ -m integration

# All tests with coverage
pytest tests/ --cov=rustchain --cov-report=html

Development

# Install in development mode
pip install -e ".[dev]"

# Run type checking
mypy rustchain/

# Format code
black rustchain/

License

MIT License

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rustchain-1.0.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rustchain-1.0.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file rustchain-1.0.0.tar.gz.

File metadata

  • Download URL: rustchain-1.0.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rustchain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a793966026a5387a46f39d9eadc916c6dc25d8a2d8aec7b7ceb45c54b52babb9
MD5 b6db6aee1b2cef6c155b3a8214ea4d97
BLAKE2b-256 a95052775b36eead86ad74a1007e69197d04ef3fe3d47e3f6bb2568d98b673b3

See more details on using hashes here.

File details

Details for the file rustchain-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rustchain-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rustchain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 266536ca138bc23e197ffc3011915f61955ba52b41cd4f6c78989c2fb172a93e
MD5 3a2a09d6eb9c657364c114fd5c2751a7
BLAKE2b-256 dd04cc1800dcdb70670027c2bdc41a681401e5e1af3027202b18ac54779f0333

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page