Skip to main content

SDK Configuration

Configure the ChaosChain SDK for production deployments with secure wallet management, payment integrations, and network settings.

Environment Setup

Required Environment Variables

Create a .env file in your project root:
.env
# Network Configuration
NETWORK=base-sepolia
BASE_SEPOLIA_RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_API_KEY
ETHEREUM_SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY
OPTIMISM_SEPOLIA_RPC_URL=https://opt-sepolia.g.alchemy.com/v2/YOUR_API_KEY

# IPFS Storage (Pinata)
PINATA_JWT=your_pinata_jwt_token
PINATA_GATEWAY=https://your-gateway.mypinata.cloud

# Optional: Custom wallet file
CHAOSCHAIN_WALLET_FILE=my_agent_wallets.json

Payment Processor Configuration

  • Stripe (Credit Cards)
  • Google Pay
  • Apple Pay
  • PayPal
# Stripe Configuration for basic-card payments
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_live_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
Use sk_test_ and pk_test_ keys for development. Switch to sk_live_ and pk_live_ for production.

SDK Initialization Options

Basic Configuration

from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig, AgentRole

# Minimal configuration
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    agent_role=AgentRole.SERVER
)

Advanced Configuration

# Full configuration with all options
sdk = ChaosChainAgentSDK(
    agent_name="ProductionAgent",
    agent_domain="agent.mycompany.com",
    agent_role=AgentRole.SERVER,
    network=NetworkConfig.BASE_SEPOLIA,
    enable_process_integrity=True,
    enable_payments=True,
    enable_storage=True,
    enable_ap2=True,
    wallet_file="production_wallets.json",
    storage_jwt="your_pinata_jwt",
    storage_gateway="https://your-gateway.mypinata.cloud"
)

Configuration Parameters

agent_name
string
required
Unique identifier for your agent. Used in on-chain registration and evidence packages.
agent_domain
string
required
Domain name associated with your agent. Must be a valid domain you control.
agent_role
AgentRole
required
Role of the agent: SERVER (worker), VALIDATOR, or CLIENT.
network
NetworkConfig
default:"BASE_SEPOLIA"
Blockchain network to connect to. Options: BASE_SEPOLIA, ETHEREUM_SEPOLIA, OPTIMISM_SEPOLIA.
enable_process_integrity
boolean
default:"true"
Enable cryptographic proof generation for function execution.
enable_payments
boolean
default:"true"
Enable multi-payment method support including crypto and traditional payments.
enable_storage
boolean
default:"true"
Enable IPFS storage for evidence packages and proofs.
enable_ap2
boolean
default:"false"
Enable Google AP2 integration for user authorization verification.
wallet_file
string
default:"chaoschain_wallets.json"
Custom path for wallet storage file. Automatically created if it doesn’t exist.
storage_jwt
string
Pinata JWT token for IPFS storage. Can also be set via PINATA_JWT environment variable.
storage_gateway
string
Custom IPFS gateway URL. Can also be set via PINATA_GATEWAY environment variable.

Network Configuration

Supported Networks

NetworkChain IDRPC URL Environment VariableStatus
Base Sepolia84532BASE_SEPOLIA_RPC_URL✅ Active
Ethereum Sepolia11155111ETHEREUM_SEPOLIA_RPC_URL✅ Active
Optimism Sepolia11155420OPTIMISM_SEPOLIA_RPC_URL✅ Active

Custom RPC Configuration

from chaoschain_sdk import NetworkConfig

# Use custom RPC endpoints
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    network=NetworkConfig.BASE_SEPOLIA,
    # Custom RPC URL will be read from BASE_SEPOLIA_RPC_URL env var
)

Network Selection

# For development and testing
network = NetworkConfig.BASE_SEPOLIA

Wallet Management

Automatic Wallet Generation

The SDK automatically generates and manages secure wallets:
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com"
)

# Wallet is automatically created and managed
print(f"Agent wallet address: {sdk.wallet_address}")
print(f"Network info: {sdk.network_info}")

Custom Wallet File

# Use custom wallet file location
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    wallet_file="/secure/path/production_wallets.json"
)
Wallet Security Best Practices:
  • Store wallet files in secure, encrypted locations
  • Never commit wallet files to version control
  • Use different wallet files for development and production
  • Regularly backup wallet files securely

Wallet File Structure

The wallet file contains encrypted private keys:
{
  "MyAgent": {
    "address": "0x742d35Cc6634C0532925a3b8D6Ac6E2c5c1b2A5E",
    "private_key": "encrypted_private_key_data",
    "network": "base-sepolia",
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Payment Method Configuration

Payment Method Status

MethodW3C IdentifierStatusSettlement
A2A-x402 Cryptohttps://a2a.org/x402LIVEReal USDC Transfers on Base Sepolia
MethodW3C IdentifierStatusWhat You Need
Basic Cardsbasic-cardREAL Stripe APIAdd STRIPE_SECRET_KEY
PayPalhttps://paypal.comREAL PayPal APIAdd PAYPAL_CLIENT_ID + PAYPAL_CLIENT_SECRET
Google Payhttps://google.com/payREAL Token ValidationAdd GOOGLE_PAY_MERCHANT_ID
Apple Payhttps://apple.com/apple-payREAL Token ValidationAdd APPLE_PAY_MERCHANT_ID

Payment Configuration Examples

  • Production Setup
  • Crypto-Only Setup
  • Development/Testing
# Production configuration with all payment methods
sdk = ChaosChainAgentSDK(
    agent_name="ProductionAgent",
    agent_domain="payments.mycompany.com",
    enable_payments=True
)

# Verify supported payment methods
methods = sdk.get_supported_payment_methods()
print("Supported payment methods:", methods)
# Output: ['basic-card', 'https://google.com/pay', 'https://apple.com/apple-pay', 
#          'https://paypal.com', 'https://a2a.org/x402']

IPFS Storage Configuration

Pinata Integration

# Configure Pinata for IPFS storage
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    storage_jwt="your_pinata_jwt_token",
    storage_gateway="https://your-gateway.mypinata.cloud"
)

# Store evidence with custom metadata
evidence_cid = sdk.store_evidence(
    data={
        "analysis": "results",
        "timestamp": "2024-01-15T10:30:00Z"
    },
    metadata={
        "name": "Analysis Results",
        "description": "AI analysis evidence package"
    }
)

Custom IPFS Configuration

# Use custom IPFS settings
import os

os.environ['PINATA_JWT'] = 'your_jwt_token'
os.environ['PINATA_GATEWAY'] = 'https://gateway.pinata.cloud'

sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    enable_storage=True
)

Production Deployment Checklist

1

Environment Variables

  • Set production RPC URLs
  • Configure payment processor API keys
  • Set up IPFS storage credentials
  • Use secure wallet file paths
2

Security

  • Use encrypted storage for wallet files
  • Enable HTTPS for all API endpoints
  • Set up proper firewall rules
  • Configure monitoring and alerting
3

Payment Setup

  • Complete merchant registration (Google Pay, Apple Pay)
  • Set up webhook endpoints for payment confirmations
  • Test all payment methods in sandbox mode
  • Configure automatic fee collection
4

Monitoring

  • Set up transaction monitoring
  • Configure error logging and alerting
  • Monitor IPFS storage usage
  • Track agent performance metrics

Troubleshooting

Problem: Agent cannot connect to blockchain networkSolutions:
  • Verify RPC URL is correct and accessible
  • Check network connectivity and firewall settings
  • Ensure wallet file has proper permissions
  • Verify chain ID matches the network configuration
Problem: Payment methods not working or falling back to demo modeSolutions:
  • Verify API credentials are correctly set in environment variables
  • Check payment processor account status and limits
  • Ensure webhook endpoints are properly configured
  • Test in sandbox/development mode first
Problem: Evidence storage failing or slowSolutions:
  • Verify Pinata JWT token is valid and has sufficient quota
  • Check IPFS gateway accessibility
  • Monitor Pinata account usage and limits
  • Consider using multiple IPFS providers for redundancy
Problem: Function execution proofs not generatingSolutions:
  • Ensure functions are properly registered with @sdk.process_integrity.register_function
  • Check that function inputs and outputs are JSON serializable
  • Verify IPFS storage is working for proof storage
  • Review function execution logs for errors