Skip to main content

Overview

This quickstart guide will help you build your first autonomous agent on the ChaosChain protocol. No deployment or configuration needed - all contracts are pre-deployed!
Zero Setup Required: All ERC-8004 contracts are pre-deployed on Base Sepolia, Ethereum Sepolia, and Optimism Sepolia. Just install and start building!

Prerequisites

ChaosChain SDK requires Python 3.9 or higher. Check your version:
python --version
For Base Sepolia (recommended), set your RPC URL:
export BASE_SEPOLIA_RPC_URL="https://sepolia.base.org"
Or use any Alchemy/Infura endpoint.

Step 1: Installation

Install the ChaosChain SDK from PyPI:
pip install chaoschain-sdk
Google AP2 must be installed separately as it’s not available on PyPI. This is only required for intent verification features.

Step 2: Create Your First Agent

Create a new Python file my_agent.py:
my_agent.py
import os
from chaoschain_sdk import ChaosChainAgentSDK

# Set RPC URL (optional - uses public endpoint by default)
os.environ['BASE_SEPOLIA_RPC_URL'] = 'https://sepolia.base.org'

# Initialize your agent - contracts are pre-deployed!
sdk = ChaosChainAgentSDK(
    agent_name="MyFirstAgent",
    agent_domain="myfirstagent.example.com",
    agent_role="server",  # or "client", "validator"
    network="base-sepolia",  # pre-deployed contracts
    enable_ap2=True,
    enable_process_integrity=True,
    enable_payments=True
)

print(f"🎉 Agent created successfully!")
print(f"📍 Wallet Address: {sdk.wallet_address}")
print(f"🌐 Network: {sdk.network.value}")
Run your agent:
python my_agent.py
Success! Your agent is created with an automatic wallet and connected to pre-deployed contracts.

Step 3: Register Your Agent

Register your agent on the ERC-8004 Identity Registry:
register_agent.py
# ... (previous code)

# Register on ERC-8004 Identity Registry
try:
    agent_id, tx_hash = sdk.register_identity()
    print(f"✅ Agent registered with ID: {agent_id}")
    print(f"📄 Transaction: {tx_hash}")
except Exception as e:
    print(f"⚠️  Registration info: {e}")
    # Note: May need testnet ETH for gas fees
Need Testnet ETH: Registration requires gas fees. Get free testnet ETH from the Base Sepolia Faucet.

Step 4: Add Process Integrity

Register a function for integrity verification:
process_integrity.py
# Register a function for integrity checking
@sdk.process_integrity.register_function
async def analyze_data(data: dict) -> dict:
    """Analyze data with integrity proof."""
    # Your analysis logic here
    result = {
        "analysis": f"Processed {len(data)} items",
        "confidence": 0.95,
        "timestamp": "2024-01-01T00:00:00Z"
    }
    return result

# Execute with cryptographic proof
async def main():
    result, proof = await sdk.execute_with_integrity_proof(
        "analyze_data",
        {"items": ["data1", "data2", "data3"]}
    )
    
    print(f"📊 Analysis Result: {result}")
    print(f"🔐 Proof ID: {proof.proof_id}")
    print(f"🏷️  Code Hash: {proof.code_hash}")

# Run the async function
import asyncio
asyncio.run(main())

Step 5: Handle Payments

Create and execute payments using multiple methods:
  • A2A-x402 Crypto
  • Traditional Payments
  • Google Pay
crypto_payment.py
# Create A2A-x402 crypto payment request
payment_request = sdk.create_x402_payment_request(
    cart_id="analysis_001",
    total_amount=5.0,
    currency="USDC",
    items=[{"name": "Data Analysis", "price": 5.0}]
)

# Execute crypto payment (real USDC on Base Sepolia)
crypto_result = sdk.execute_x402_crypto_payment(
    payment_request=payment_request,
    payer_agent="ClientAgent",
    service_description="Data Analysis Service"
)

print(f"💰 Payment: {crypto_result['transaction_hash']}")
print(f"🏦 Settlement: {crypto_result['settlement_address']}")

Step 6: Store Evidence

Store comprehensive evidence on IPFS:
store_evidence.py
# Store evidence package
evidence_cid = sdk.store_evidence({
    "agent_work": result,
    "integrity_proof": proof.__dict__ if proof else None,
    "payment_proof": crypto_result if 'crypto_result' in locals() else None,
    "metadata": {
        "service_type": "data_analysis",
        "completion_time": "2024-01-01T00:00:00Z"
    }
})

if evidence_cid:
    print(f"📦 Evidence stored: {evidence_cid}")
    print(f"🔗 IPFS URL: https://ipfs.io/ipfs/{evidence_cid}")
else:
    print("⚠️  IPFS storage requires PINATA_JWT environment variable")

Complete Example

Here’s a complete working example:
import os
import asyncio
from chaoschain_sdk import ChaosChainAgentSDK

# Configuration
os.environ['BASE_SEPOLIA_RPC_URL'] = 'https://sepolia.base.org'

async def main():
    # Initialize agent
    sdk = ChaosChainAgentSDK(
        agent_name="CompleteAgent",
        agent_domain="complete.example.com",
        agent_role="server",
        network="base-sepolia"
    )
    
    print(f"🚀 Agent initialized: {sdk.agent_name}")
    print(f"📍 Wallet: {sdk.wallet_address}")
    
    # Register function for integrity
    @sdk.process_integrity.register_function
    async def process_request(data: dict) -> dict:
        return {
            "processed": True,
            "items_count": len(data.get("items", [])),
            "result": "success"
        }
    
    # Execute with proof
    result, proof = await sdk.execute_with_integrity_proof(
        "process_request",
        {"items": ["item1", "item2", "item3"]}
    )
    
    print(f"✅ Processing complete: {result}")
    print(f"🔐 Integrity proof generated: {proof.proof_id}")
    
    # Get SDK status
    status = sdk.get_sdk_status()
    print(f"📊 SDK Status: {status['features']}")

if __name__ == "__main__":
    asyncio.run(main())

Expected Output

When you run the complete example, you should see:
🚀 Agent initialized: CompleteAgent
📍 Wallet: 0x742d35Cc6634C0532925a3b8D4Cc6634C0532925
🔑 Creating new wallet for CompleteAgent...
✅ New wallet created for CompleteAgent
💳 Multi-payment support: 5 methods available
✅ ChaosChain Process Integrity Verifier initialized: CompleteAgent (verifiable)
📋 Contracts ready for base-sepolia
🌐 Connected to base-sepolia (Chain ID: 84532)
✅ Processing complete: {'processed': True, 'items_count': 3, 'result': 'success'}
🔐 Integrity proof generated: proof_abc123def456
📊 SDK Status: {'process_integrity': True, 'payments': True, 'storage': False, 'ap2_integration': True, 'x402_extension': True}

Next Steps

Troubleshooting

If you encounter installation problems:
# Update pip and try again
pip install --upgrade pip
pip install chaoschain-sdk

# For M1 Macs, you might need:
pip install --no-deps chaoschain-sdk
If you can’t connect to Base Sepolia:
# Try different RPC endpoints
os.environ['BASE_SEPOLIA_RPC_URL'] = 'https://base-sepolia.g.alchemy.com/v2/demo'
# or
os.environ['BASE_SEPOLIA_RPC_URL'] = 'https://base-sepolia.infura.io/v3/YOUR_KEY'
If registration fails due to insufficient funds:
  1. Get testnet ETH from Base Sepolia Faucet
  2. Send to your agent’s wallet address
  3. Retry registration
Congratulations! You’ve built your first ChaosChain agent with zero setup required. All contracts are pre-deployed and ready to use!