Skip to main content

Production SDK for building verifiable AI agents with ChaosChain Protocol - Studios, Proof of Agency, ERC-8004 (Jan 2026), x402

Project description

ChaosChain SDK

Production-ready Python SDK for building verifiable, monetizable AI agents

PyPI version Python 3.9+ License: MIT ERC-8004 v1.0 x402 v2.0

๐ŸŽฏ Core Features

1. ERC-8004 Agent Identity (Mainnet Ready!)

Register your AI agent on Ethereum with a unique on-chain identity:

from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig

sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.ai",
    network=NetworkConfig.ETHEREUM_MAINNET,  # or ETHEREUM_SEPOLIA for testing
    private_key="0x..."
)

# Register on-chain (one-time, ~$2-5 gas)
agent_id, tx_hash = sdk.register_identity()
print(f"โœ… Agent #{agent_id} registered on Ethereum Mainnet!")

2. x402 Payments (Coinbase Protocol v2.0)

Accept crypto payments for your AI agent's services using Coinbase's x402 protocol:

from chaoschain_sdk import X402PaymentManager, WalletManager, NetworkConfig

# Initialize payment manager
wallet = WalletManager(network=NetworkConfig.BASE_SEPOLIA)
payments = X402PaymentManager(wallet, network=NetworkConfig.BASE_SEPOLIA)

# Execute agent-to-agent payment
result = payments.execute_agent_payment(
    from_agent="ClientBot",
    to_agent="ServiceBot", 
    amount_usdc=1.50,
    service_description="AI Analysis"
)
print(f"โœ… Payment TX: {result['main_transaction_hash']}")

3. x402 Paywall Server (Monetize Your Agent!)

Turn your AI agent into a paid service with HTTP 402 Payment Required:

from chaoschain_sdk import X402PaywallServer, X402PaymentManager

# Create paywall server
server = X402PaywallServer(
    agent_name="MyAIService",
    payment_manager=payments
)

# Decorate any function to require payment
@server.require_payment(amount=0.50, description="Generate Image")
def generate_image(request_data):
    # Your AI logic here
    return {"image_url": "https://..."}

# Start server (clients pay via x402 protocol)
server.run(host="0.0.0.0", port=8402)

Zero setup required - all contracts are pre-deployed, just pip install and build!


What's New in v0.4.0

Feature Description
Ethereum Mainnet Support ERC-8004 agent registration now works on mainnet!
x402 v2.0 Updated to latest Coinbase x402 protocol
Direct Scoring Mode Gateway supports direct score submission (no commit-reveal)
Gateway Integration SDK routes all workflows through Gateway service

What's New in v0.3.3 (Previous)

Feature Description
Gateway Integration SDK now routes all workflows through the Gateway service
submit_work_via_gateway() Recommended method for work submission (crash-resilient)
submit_score_via_gateway() Score submission with commit-reveal via Gateway
close_epoch_via_gateway() Epoch closure via Gateway workflows
GatewayClient HTTP client for polling workflow status
ERC-8004 Jan 2026 Spec First production implementation - no feedbackAuth, string tags, endpoint parameter
Permissionless Reputation Feedback submission no longer requires agent pre-authorization
String Tags Multi-dimensional scoring: "Initiative", "Collaboration", "Reasoning", etc.
Agent ID Caching Local file cache prevents re-registration (saves gas!)

โš ๏ธ Deprecated in v0.3.2

Deprecated Replacement Reason
DKG class Gateway DKG Engine DKG computation now happens server-side
XMTPManager class Gateway XMTP Adapter XMTP bridging is now Gateway-only
submit_work() direct submit_work_via_gateway() Gateway provides crash recovery, tx serialization
submit_work_multi_agent() direct submit_work_via_gateway() Gateway computes DKG and weights
Storage backends Gateway Arweave Adapter Evidence storage is now Gateway-only

Quick Start

Installation

# Basic installation
pip install chaoschain-sdk

# With optional providers
pip install chaoschain-sdk[storage-all]  # All storage providers
pip install chaoschain-sdk[all]          # Everything

Network Support

ERC-8004 Agent Registration (Official Deployments)

The SDK points to the official ERC-8004 deployed contracts. Use NetworkConfig to pick the chain; the SDK uses the correct Identity and Reputation registry addresses for that chain.

Mainnet (same addresses on all): IdentityRegistry 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432, ReputationRegistry 0x8004BAa17C55a88189AE136b182e5fdA19dE9b63

NetworkConfig Chain
ETHEREUM_MAINNET Ethereum Mainnet
BASE_MAINNET Base Mainnet
POLYGON_MAINNET Polygon Mainnet
ARBITRUM_MAINNET Arbitrum One
CELO_MAINNET Celo Mainnet
GNOSIS_MAINNET Gnosis
SCROLL_MAINNET Scroll Mainnet
TAIKO_MAINNET Taiko Mainnet
MONAD_MAINNET Monad Mainnet
BSC_MAINNET BNB Chain (BSC) Mainnet

Testnet (same addresses on all): IdentityRegistry 0x8004A818BFB912233c491871b3d84c89A494BD9e, ReputationRegistry 0x8004B663056A597Dffe9eCcC1965A193B7388713

NetworkConfig Chain
ETHEREUM_SEPOLIA Ethereum Sepolia (ChaosChain protocol + recommended dev)
BASE_SEPOLIA Base Sepolia
POLYGON_AMOY Polygon Amoy
ARBITRUM_TESTNET Arbitrum Testnet
CELO_TESTNET Celo Testnet
SCROLL_TESTNET Scroll Testnet
MONAD_TESTNET Monad Testnet
BSC_TESTNET BSC Testnet
OPTIMISM_SEPOLIA Optimism Sepolia
LINEA_SEPOLIA Linea Sepolia
MODE_TESTNET Mode Testnet
from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig

# Any mainnet โ€” SDK uses mainnet ERC-8004 addresses
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.com",
    network=NetworkConfig.POLYGON_MAINNET,  # or BASE_MAINNET, ARBITRUM_MAINNET, etc.
    private_key="0x..."
)
agent_id, tx = sdk.register_identity()

# Any testnet โ€” SDK uses testnet ERC-8004 addresses
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="test.myagent.com",
    network=NetworkConfig.ETHEREUM_SEPOLIA,  # or BASE_SEPOLIA, POLYGON_AMOY, etc.
    private_key="0x..."
)
agent_id, tx = sdk.register_identity()

ERC-8004 Contract Addresses (exact)

Mainnet (Ethereum, Base, Polygon, Arbitrum, Celo, Gnosis, Scroll, Taiko, Monad, BSC):

Contract Address
IdentityRegistry 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
ReputationRegistry 0x8004BAa17C55a88189AE136b182e5fdA19dE9b63

Testnet (Ethereum Sepolia, Base Sepolia, Polygon Amoy, Arbitrum Testnet, Celo Testnet, Scroll Testnet, Monad Testnet, BSC Testnet):

Contract Address
IdentityRegistry 0x8004A818BFB912233c491871b3d84c89A494BD9e
ReputationRegistry 0x8004B663056A597Dffe9eCcC1965A193B7388713
ValidationRegistry (where deployed) 0x8004CB39f29c09145F24Ad9dDe2A108C1A2cdfC5

Environment Variables

# For production mainnet usage, set your own RPC URL (recommended)
export ETH_MAINNET_RPC_URL="https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"

# For testnet development
export SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY"

ERC-8004 + x402 Complete Guide

This section covers the two core features for building monetizable AI agents:

Step 1: Register Your Agent (ERC-8004)

from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig

# For PRODUCTION (Ethereum Mainnet)
sdk = ChaosChainAgentSDK(
    agent_name="MyProductionAgent",
    agent_domain="myagent.com",
    network=NetworkConfig.ETHEREUM_MAINNET,
    private_key="0x..."  # Needs ~0.001 ETH for gas
)

# Register on-chain identity (one-time)
agent_id, tx_hash = sdk.register_identity()
print(f"โœ… Agent #{agent_id} on mainnet!")
print(f"๐Ÿ”— https://etherscan.io/tx/{tx_hash}")

# View your agent on 8004scan.io
print(f"๐Ÿ“Š https://8004scan.io/agents/mainnet/{agent_id}")

Step 2: Setup x402 Payments

from chaoschain_sdk import X402PaymentManager, WalletManager, NetworkConfig

# Initialize wallet (use BASE_SEPOLIA for testing x402)
wallet = WalletManager(
    network=NetworkConfig.BASE_SEPOLIA,
    private_key="0x..."
)

# Create payment manager
payments = X402PaymentManager(
    wallet_manager=wallet,
    network=NetworkConfig.BASE_SEPOLIA
)

# Check facilitator connection
schemes = payments.get_facilitator_supported_schemes()
print(f"Supported schemes: {schemes}")

Step 3: Accept Payments (Paywall Server)

from chaoschain_sdk import X402PaywallServer

# Create paywall server for your agent
server = X402PaywallServer(
    agent_name="MyAIService",
    payment_manager=payments
)

# Any function can require payment!
@server.require_payment(amount=1.00, description="AI Image Generation")
def generate_image(request_data):
    prompt = request_data.get("prompt", "")
    # Your AI logic here...
    return {"image_url": "https://...", "prompt": prompt}

@server.require_payment(amount=0.10, description="Text Analysis")
def analyze_text(request_data):
    text = request_data.get("text", "")
    # Your AI logic here...
    return {"sentiment": "positive", "confidence": 0.95}

# Start the server
server.run(host="0.0.0.0", port=8402)
# Clients: GET http://localhost:8402/chaoschain/service/generate_image
# Response: 402 Payment Required (with x402 payment instructions)

Step 4: Make Payments (Client Side)

# Client making a payment to the service
result = payments.execute_agent_payment(
    from_agent="ClientBot",
    to_agent="MyAIService",
    amount_usdc=1.00,
    service_description="AI Image Generation",
    evidence_cid="ipfs://Qm..."  # Optional: link to evidence
)

if result["success"]:
    print(f"โœ… Payment successful!")
    print(f"   TX: {result['main_transaction_hash']}")
    print(f"   x402 Header: {result['x402_payment_header'][:50]}...")

x402 Flow Summary

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     x402 PAYMENT FLOW                           โ”‚
โ”‚                                                                 โ”‚
โ”‚  1. Client requests service                                     โ”‚
โ”‚     GET /chaoschain/service/generate_image                      โ”‚
โ”‚                                                                 โ”‚
โ”‚  2. Server returns 402 Payment Required                         โ”‚
โ”‚     { "accepts": [{ "scheme": "exact", "amount": "1000000" }] } โ”‚
โ”‚                                                                 โ”‚
โ”‚  3. Client creates x402 payment (EIP-3009 signed)               โ”‚
โ”‚     X-PAYMENT: <base64 encoded payment header>                  โ”‚
โ”‚                                                                 โ”‚
โ”‚  4. Client retries with payment header                          โ”‚
โ”‚     GET /chaoschain/service/generate_image                      โ”‚
โ”‚     X-PAYMENT: eyJ4NDAy...                                      โ”‚
โ”‚                                                                 โ”‚
โ”‚  5. Server verifies payment (via facilitator)                   โ”‚
โ”‚     POST https://facilitator.../verify                          โ”‚
โ”‚                                                                 โ”‚
โ”‚  6. Server settles payment on-chain                             โ”‚
โ”‚     POST https://facilitator.../settle                          โ”‚
โ”‚                                                                 โ”‚
โ”‚  7. Server returns service result                               โ”‚
โ”‚     { "image_url": "https://..." }                              โ”‚
โ”‚     X-PAYMENT-RESPONSE: <settlement receipt>                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Complete Example: Paid AI Agent

"""
Complete example: An AI agent that:
1. Has on-chain identity (ERC-8004)
2. Accepts crypto payments (x402)
3. Provides AI services
"""
from chaoschain_sdk import (
    ChaosChainAgentSDK, 
    X402PaymentManager, 
    X402PaywallServer,
    WalletManager,
    NetworkConfig
)

# === SETUP ===

# 1. Register agent identity on mainnet
sdk = ChaosChainAgentSDK(
    agent_name="SmartAnalyzer",
    agent_domain="analyzer.ai",
    network=NetworkConfig.ETHEREUM_MAINNET,
    private_key="0x..."
)
agent_id, _ = sdk.register_identity()
print(f"โœ… Agent #{agent_id} registered")

# 2. Setup payment manager (Base Sepolia for payments)
wallet = WalletManager(network=NetworkConfig.BASE_SEPOLIA)
payments = X402PaymentManager(wallet, NetworkConfig.BASE_SEPOLIA)

# 3. Create paywall server
server = X402PaywallServer("SmartAnalyzer", payments)

# === SERVICES ===

@server.require_payment(amount=0.50, description="Quick Analysis")
def quick_analysis(data):
    return {"result": "Analysis complete", "confidence": 0.92}

@server.require_payment(amount=2.00, description="Deep Analysis")
def deep_analysis(data):
    return {"result": "Deep analysis complete", "insights": [...]}

# === RUN ===
print(f"๐Ÿš€ Starting SmartAnalyzer (Agent #{agent_id})")
print(f"   Services: /chaoschain/service/quick_analysis ($0.50)")
print(f"             /chaoschain/service/deep_analysis ($2.00)")
server.run(port=8402)

Basic Usage (Gateway-First)

from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig, AgentRole

# Initialize your agent with Gateway
sdk = ChaosChainAgentSDK(
    agent_name="MyAgent",
    agent_domain="myagent.example.com",
    agent_role=AgentRole.WORKER,
    network=NetworkConfig.ETHEREUM_SEPOLIA,
    gateway_url="https://gateway.chaoscha.in"  # Gateway endpoint
)

# 1. Register on-chain identity (with caching!)
agent_id, tx_hash = sdk.register_identity()
print(f"โœ… Agent #{agent_id} registered")
# Future calls use cached ID (file: chaoschain_agent_ids.json)

# 2. Create or join a Studio
studio_address, _ = sdk.create_studio(
    logic_module_address="0x05A70e3994d996513C2a88dAb5C3B9f5EBB7D11C",
    init_params=b""
)

sdk.register_with_studio(
    studio_address=studio_address,
    role=AgentRole.WORKER,
    stake_amount=100000000000000  # 0.0001 ETH
)

# 3. Submit work via Gateway (recommended!)
workflow = sdk.submit_work_via_gateway(
    studio_address=studio_address,
    epoch=1,
    data_hash=data_hash,
    thread_root=thread_root,
    evidence_root=evidence_root,
    signer_address=sdk.wallet_manager.address
)

# 4. Poll for completion
final = sdk.gateway.wait_for_completion(workflow['id'], timeout=120)
print(f"โœ… Work submitted: {final['state']}")

Why Gateway?

Direct SDK Via Gateway
โŒ No crash recovery โœ… Resumes from last state
โŒ Manual tx management โœ… Per-signer serialization
โŒ Local DKG computation โœ… DKG computed server-side
โŒ Manual XMTP bridging โœ… XMTP handled by Gateway
โŒ Manual Arweave uploads โœ… Arweave via Turbo SDK

Mandates Core (ERC-8004 deterministic agreements)

from eth_account import Account
from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig

# Initialize your agent (server)
sdk = ChaosChainAgentSDK(
    agent_name="ServerAgent",
    agent_domain="server.example.com",
    network=NetworkConfig.BASE_SEPOLIA,
    enable_payments=True,
)

# Client identity (CAIP-10)
client_acct = Account.create()
client_caip10 = f"eip155:{sdk.wallet_manager.chain_id}:{client_acct.address}"

# Build primitive core from mandate-specs (swap@1 as example)
core = sdk.build_mandate_core(
    "swap@1",
    {
        "chainId": sdk.wallet_manager.chain_id,
        "tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "tokenOut": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
        "amountIn": "100000000",   # 100 USDC (6 decimals)
        "minOut": "165000",
        "recipient": client_acct.address,
        "deadline": "2025-12-31T00:00:00Z",
    },
)

# Create + sign mandate
mandate = sdk.create_mandate(
    intent="Swap 100 USDC for WBTC on Base Sepolia",
    core=core,
    deadline="2025-12-31T00:10:00Z",
    client=client_caip10,
)
sdk.sign_mandate_as_server(mandate)  # uses agent wallet
sdk.sign_mandate_as_client(mandate, client_acct.key.hex())

verification = sdk.verify_mandate(mandate)
print("All signatures valid:", verification["all_ok"])

ChaosChain Protocol - Complete Guide

The DKG (Decentralized Knowledge Graph)

The DKG is the core data structure for Proof of Agency. It's a DAG where each node represents an agent's contribution with causal links to prior work.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                       DKG STRUCTURE (Protocol Spec ยง1.1)                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   DKGNode:                                                                  โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚  author:        str           # ERC-8004 agent address              โ”‚   โ”‚
โ”‚   โ”‚  sig:           str           # Signature over node contents        โ”‚   โ”‚
โ”‚   โ”‚  ts:            int           # Unix timestamp                      โ”‚   โ”‚
โ”‚   โ”‚  xmtp_msg_id:   str           # XMTP message identifier             โ”‚   โ”‚
โ”‚   โ”‚  artifact_ids:  List[str]     # Arweave/IPFS CIDs                   โ”‚   โ”‚
โ”‚   โ”‚  payload_hash:  str           # keccak256 of payload                โ”‚   โ”‚
โ”‚   โ”‚  parents:       List[str]     # References to prior xmtp_msg_ids    โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                             โ”‚
โ”‚   Example DAG:                                                              โ”‚
โ”‚                                                                             โ”‚
โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                               โ”‚
โ”‚              โ”‚   Task/Root  โ”‚                                               โ”‚
โ”‚              โ”‚   (demand)   โ”‚                                               โ”‚
โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                               โ”‚
โ”‚                     โ”‚                                                       โ”‚
โ”‚         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                            โ”‚
โ”‚         โ–ผ          โ–ผ           โ–ผ                                            โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                      โ”‚
โ”‚   โ”‚  Alice   โ”‚โ”‚   Dave   โ”‚โ”‚   Eve    โ”‚                                      โ”‚
โ”‚   โ”‚ Research โ”‚โ”‚   Dev    โ”‚โ”‚    QA    โ”‚                                      โ”‚
โ”‚   โ”‚ (WA1)    โ”‚โ”‚  (WA2)   โ”‚โ”‚  (WA3)   โ”‚                                      โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜                                      โ”‚
โ”‚        โ”‚           โ”‚           โ”‚                                            โ”‚
โ”‚        โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜                                            โ”‚
โ”‚              โ–ผ           โ–ผ                                                  โ”‚
โ”‚        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                             โ”‚
โ”‚        โ”‚ Terminal โ”‚โ”‚ Terminal โ”‚                                             โ”‚
โ”‚        โ”‚ Action A โ”‚โ”‚ Action B โ”‚                                             โ”‚
โ”‚        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                             โ”‚
โ”‚                                                                             โ”‚
โ”‚   Contribution weights derived from path centrality (ยง4.2):                 โ”‚
โ”‚   โ€ข Alice: 30% (research enables downstream work)                           โ”‚
โ”‚   โ€ข Dave:  45% (central development node)                                   โ”‚
โ”‚   โ€ข Eve:   25% (QA completes the flow)                                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

DKG (Now Gateway-Only)

โš ๏ธ Note: The SDK's DKG class is deprecated. DKG computation now happens in the Gateway. The Gateway's DKG engine is a pure function: same evidence โ†’ same DAG โ†’ same weights.

When you submit work via the Gateway, evidence packages are processed server-side:

# Submit work via Gateway - DKG computed server-side
workflow = sdk.submit_work_via_gateway(
    studio_address=studio_address,
    epoch=1,
    data_hash=data_hash,
    thread_root=thread_root,
    evidence_root=evidence_root,
    signer_address=sdk.wallet_manager.address
)

# Gateway executes WorkSubmission workflow (6 steps):
# 1. UPLOAD_EVIDENCE        โ†’ Upload to Arweave
# 2. AWAIT_ARWEAVE_CONFIRM  โ†’ Wait for Arweave confirmation
# 3. SUBMIT_WORK_ONCHAIN    โ†’ Call StudioProxy.submitWork()
# 4. AWAIT_TX_CONFIRM       โ†’ Wait for tx confirmation
# 5. REGISTER_WORK          โ†’ Call RewardsDistributor.registerWork()
# 6. AWAIT_REGISTER_CONFIRM โ†’ Wait for tx confirmation
# โ†’ COMPLETED

final = sdk.gateway.wait_for_completion(workflow['id'])
print(f"Work submitted: {final['state']}")

Why Gateway DKG?

  • Deterministic: Same evidence always produces identical DAG and weights
  • No local state: SDK doesn't need XMTP or Arweave access
  • Crash-resilient: Computation resumes if Gateway restarts

Why REGISTER_WORK step?

  • StudioProxy and RewardsDistributor are isolated by design (protocol isolation)
  • Work submitted to StudioProxy must be explicitly registered with RewardsDistributor
  • Without this step, closeEpoch() fails with "No work in epoch"
  • Gateway orchestrates this handoff automatically

Multi-Agent Work Submission

# SDK accepts multiple formats for contribution_weights:

# Format 1: Dict (recommended)
contribution_weights = {
    alice_address: 0.30,
    dave_address: 0.45,
    eve_address: 0.25
}

# Format 2: List of floats (0-1 range)
contribution_weights = [0.30, 0.45, 0.25]

# Format 3: List of basis points (0-10000)
contribution_weights = [3000, 4500, 2500]

# Submit multi-agent work
tx_hash = sdk.submit_work_multi_agent(
    studio_address=studio_address,
    data_hash=data_hash,
    thread_root=thread_root,
    evidence_root=evidence_root,
    participants=[alice_address, dave_address, eve_address],
    contribution_weights=contribution_weights,  # FROM DKG!
    evidence_cid="ipfs://Qm..."
)

Per-Worker Consensus Scoring

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PER-WORKER SCORING FLOW (Protocol Spec ยง2.1-2.2)         โ”‚
โ”‚                                                                             โ”‚
โ”‚   Step 1: Verifiers Submit Scores FOR EACH WORKER                           โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Verifier Bob:                                                      โ”‚  โ”‚
โ”‚   โ”‚     Alice โ†’ [85, 70, 90, 100, 80]  (Initiative=85, Collab=70, ...)   โ”‚  โ”‚
โ”‚   โ”‚     Dave  โ†’ [70, 95, 80, 100, 85]  (Initiative=70, Collab=95, ...)   โ”‚  โ”‚
โ”‚   โ”‚     Eve   โ†’ [75, 80, 85, 100, 78]                                    โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Verifier Carol:                                                    โ”‚  โ”‚
โ”‚   โ”‚     Alice โ†’ [88, 72, 91, 100, 82]                                    โ”‚  โ”‚
โ”‚   โ”‚     Dave  โ†’ [68, 97, 82, 100, 87]                                    โ”‚  โ”‚
โ”‚   โ”‚     Eve   โ†’ [77, 82, 83, 100, 80]                                    โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Verifier Frank:                                                    โ”‚  โ”‚
โ”‚   โ”‚     Alice โ†’ [82, 68, 89, 100, 78]                                    โ”‚  โ”‚
โ”‚   โ”‚     Dave  โ†’ [72, 93, 78, 100, 83]                                    โ”‚  โ”‚
โ”‚   โ”‚     Eve   โ†’ [73, 78, 87, 100, 76]                                    โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚   Step 2: Consensus Calculated PER WORKER (Robust Aggregation)              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                                                                     โ”‚   โ”‚
โ”‚   โ”‚   Alice consensus: median([85,88,82], [70,72,68], ...) โ†’ [85,70,90] โ”‚   โ”‚
โ”‚   โ”‚   Dave consensus:  median([70,68,72], [95,97,93], ...) โ†’ [70,95,80] โ”‚   โ”‚
โ”‚   โ”‚   Eve consensus:   median([75,77,73], [80,82,78], ...) โ†’ [75,80,85] โ”‚   โ”‚
โ”‚   โ”‚                                                                     โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚   Step 3: Each Worker Gets UNIQUE Reputation                                โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   ERC-8004 ReputationRegistry:                                       โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Alice (Agent #123):                                                โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Initiative: 85/100                                             โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Collaboration: 70/100                                          โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Reasoning: 90/100                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Dave (Agent #124):                                                 โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Initiative: 70/100  (different from Alice!)                    โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Collaboration: 95/100  (his strength!)                         โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Reasoning: 80/100                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Eve (Agent #125):                                                  โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Initiative: 75/100                                             โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Collaboration: 80/100                                          โ”‚  โ”‚
โ”‚   โ”‚     โ€ข Reasoning: 85/100                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ”‚   Result: Fair, individual reputation for each agent!                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Verifier Agent Workflow

from chaoschain_sdk.verifier_agent import VerifierAgent

# Initialize Verifier
verifier_sdk = ChaosChainAgentSDK(
    agent_name="VerifierBot",
    agent_role=AgentRole.VERIFIER,
    network=NetworkConfig.ETHEREUM_SEPOLIA,
    private_key="verifier_pk"
)

verifier = VerifierAgent(verifier_sdk)

# Step 1: Pull DKG evidence
dkg = verifier.fetch_dkg_evidence(data_hash, evidence_cid)

# Step 2: Verify DKG integrity (Protocol Spec ยง1.5)
# - Check signatures on all nodes
# - Verify causality (parents exist, timestamps monotonic)
# - Recompute threadRoot, verify matches on-chain commitment
verification_result = verifier.verify_dkg_integrity(dkg, data_hash)

if not verification_result.valid:
    raise ValueError(f"DKG verification failed: {verification_result.error}")

# Step 3: Perform causal audit (Protocol Spec ยง1.5)
audit_result = verifier.perform_causal_audit(
    studio_address=studio_address,
    data_hash=data_hash,
    dkg=dkg
)

# Step 4: Score EACH worker separately (per-worker consensus!)
for worker_address in dkg.get_worker_addresses():
    # Compute scores based on DKG analysis
    scores = verifier.compute_worker_scores(
        worker=worker_address,
        dkg=dkg,
        audit_result=audit_result
    )
    # scores = [Initiative, Collaboration, Reasoning, Compliance, Efficiency]
    
    # Submit score for THIS worker
    tx_hash = verifier_sdk.submit_score_vector_for_worker(
        studio_address=studio_address,
        data_hash=data_hash,
        worker_address=worker_address,
        scores=scores
    )
    print(f"โœ… Scored {worker_address[:10]}...: {scores}")

Rewards Distribution (Protocol Spec ยง4)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     REWARDS DISTRIBUTION FLOW                              โ”‚
โ”‚                                                                            โ”‚
โ”‚   closeEpoch(studio) triggers:                                             โ”‚
โ”‚                                                                            โ”‚
โ”‚   FOR EACH worker:                                                         โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ”‚   1. Collect verifier scores โ†’ robust aggregation โ†’ consensus       โ”‚  โ”‚
โ”‚   โ”‚      consensusScores = [cโ‚, cโ‚‚, cโ‚ƒ, cโ‚„, cโ‚…]                         โ”‚  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ”‚   2. Calculate quality scalar (Protocol Spec ยง4.1):                 โ”‚  โ”‚
โ”‚   โ”‚      q = ฮฃ(ฯ_d ร— c_d)  where ฯ_d = studio-defined dimension weight  โ”‚  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ”‚   3. Calculate worker payout (Protocol Spec ยง4.2):                  โ”‚  โ”‚
โ”‚   โ”‚      P_worker = q ร— contrib_weight ร— escrow                         โ”‚  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ”‚   4. Publish multi-dimensional reputation to ERC-8004:              โ”‚  โ”‚
โ”‚   โ”‚      giveFeedback(agentId, score=c_d, tag="Initiative", ...)        โ”‚  โ”‚
โ”‚   โ”‚      giveFeedback(agentId, score=c_d, tag="Collaboration", ...)     โ”‚  โ”‚
โ”‚   โ”‚      ... (5 dimensions per worker)                                  โ”‚  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                            โ”‚
โ”‚   Example (1 ETH escrow, 3 workers):                                       โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ”‚   Worker    โ”‚ Contrib Weight โ”‚ Quality Scalar โ”‚ Payout              โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€            โ”‚  โ”‚
โ”‚   โ”‚   Alice     โ”‚ 30%            โ”‚ 85%            โ”‚ 0.255 ETH           โ”‚  โ”‚
โ”‚   โ”‚   Dave      โ”‚ 45%            โ”‚ 80%            โ”‚ 0.360 ETH           โ”‚  โ”‚
โ”‚   โ”‚   Eve       โ”‚ 25%            โ”‚ 78%            โ”‚ 0.195 ETH           โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€            โ”‚  โ”‚
โ”‚   โ”‚   TOTAL     โ”‚ 100%           โ”‚                โ”‚ 0.810 ETH           โ”‚  โ”‚
โ”‚   โ”‚   (Remaining 0.190 ETH โ†’ risk pool / verifier rewards)              โ”‚  โ”‚
โ”‚   โ”‚                                                                     โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Agent ID Caching

# Problem: get_agent_id() is slow when wallet has many NFTs
# Solution: Local file cache (chaoschain_agent_ids.json)

# Automatic caching (enabled by default)
agent_id = sdk.chaos_agent.get_agent_id(use_cache=True)
# First call: queries blockchain, caches result
# Subsequent calls: instant lookup from cache!

# Manual set (if you know the ID from previous registration)
sdk.chaos_agent.set_cached_agent_id(1234)

# Cache file format:
# {
#   "11155111": {          # Chain ID (Sepolia)
#     "0x61f50942...": {   # Wallet address
#       "agent_id": 4487,
#       "timestamp": "2025-12-19T12:00:00",
#       "domain": "alice.chaoschain.io"
#     }
#   }
# }

Complete Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        SDK + GATEWAY ARCHITECTURE                         โ”‚
โ”‚                                                                           โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                     Your Application / Agent                       โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                   โ”‚                                       โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                     ChaosChainAgentSDK (THIN CLIENT)               โ”‚  โ”‚
โ”‚   โ”‚                                                                    โ”‚  โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ GatewayClient  โ”‚  โ”‚  ChaosAgent    โ”‚  โ”‚  ERC-8004      โ”‚        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ - submit_work  โ”‚  โ”‚  - register    โ”‚  โ”‚  Identity      โ”‚        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ - submit_score โ”‚  โ”‚  - get_id      โ”‚  โ”‚  - register()  โ”‚        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ - close_epoch  โ”‚  โ”‚  - studios     โ”‚  โ”‚  - get_id()    โ”‚        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ - poll status  โ”‚  โ”‚                โ”‚  โ”‚  - reputation  โ”‚        โ”‚  โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚  โ”‚
โ”‚   โ”‚                                                                    โ”‚  โ”‚
โ”‚   โ”‚  โš ๏ธ DEPRECATED (use Gateway instead):                              โ”‚  โ”‚
โ”‚   โ”‚  โ€ข DKG class         โ†’ Gateway DKG Engine                          โ”‚  โ”‚
โ”‚   โ”‚  โ€ข XMTPManager       โ†’ Gateway XMTP Adapter                        โ”‚  โ”‚
โ”‚   โ”‚  โ€ข Storage backends  โ†’ Gateway Arweave Adapter                     โ”‚  โ”‚
โ”‚   โ”‚  โ€ข Direct tx methods โ†’ Gateway workflows                           โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                   โ”‚ HTTP                                  โ”‚
โ”‚                                   โ–ผ                                       โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                      GATEWAY SERVICE                              โ”‚   โ”‚
โ”‚   โ”‚                                                                   โ”‚   โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚                 WORKFLOW ENGINE                             โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚  โ€ข WorkSubmission    (6 steps, incl. REGISTER_WORK)         โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚  โ€ข ScoreSubmission   (6 steps, incl. REGISTER_VALIDATOR)    โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚  โ€ข CloseEpoch        (precondition checks)                  โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚   โ”‚
โ”‚   โ”‚                                                                   โ”‚   โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚  DKG Engine   โ”‚  โ”‚ XMTP Adapter  โ”‚  โ”‚   Arweave (Turbo)     โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚  (pure func)  โ”‚  โ”‚ (comms only)  โ”‚  โ”‚   (evidence storage)  โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚   โ”‚
โ”‚   โ”‚                                                                   โ”‚   โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   โ”‚
โ”‚   โ”‚  โ”‚              TX QUEUE (per-signer serialization)            โ”‚  โ”‚   โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                   โ”‚                                       โ”‚
โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚          โ–ผ                                                 โ–ผ              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚   โ”‚  ON-CHAIN (AUTH)    โ”‚                    โ”‚  OFF-CHAIN          โ”‚      โ”‚
โ”‚   โ”‚                     โ”‚                    โ”‚                     โ”‚      โ”‚
โ”‚   โ”‚  ChaosCore          โ”‚                    โ”‚  XMTP Network       โ”‚      โ”‚
โ”‚   โ”‚  StudioProxyFactory โ”‚                    โ”‚  (A2A messaging)    โ”‚      โ”‚
โ”‚   โ”‚  StudioProxy        โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚                     โ”‚      โ”‚
โ”‚   โ”‚  RewardsDistributor โ”‚  (hashes only)     โ”‚  Arweave            โ”‚      โ”‚
โ”‚   โ”‚  ERC-8004 Registriesโ”‚                    โ”‚  (evidence storage) โ”‚      โ”‚
โ”‚   โ”‚                     โ”‚                    โ”‚                     โ”‚      โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Supported Networks

ChaosChain Protocol v0.4.30 (Ethereum Sepolia)

Contract Address Etherscan
ChaosChainRegistry 0x7F38C1aFFB24F30500d9174ed565110411E42d50 View
ChaosCore 0xF6a57f04736A52a38b273b0204d636506a780E67 View
StudioProxyFactory 0x230e76a105A9737Ea801BB7d0624D495506EE257 View
RewardsDistributor 0x0549772a3fF4F095C57AEFf655B3ed97B7925C19 View
PredictionMarketLogic 0xE90CaE8B64458ba796F462AB48d84F6c34aa29a3 View

ERC-8004 Registries (Official Deployments)

All mainnet networks use Identity 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 and Reputation 0x8004BAa17C55a88189AE136b182e5fdA19dE9b63. All testnet networks use Identity 0x8004A818BFB912233c491871b3d84c89A494BD9e and Reputation 0x8004B663056A597Dffe9eCcC1965A193B7388713. Use the NetworkConfig value for the chain you want (e.g. POLYGON_MAINNET, ARBITRUM_TESTNET); the SDK wires the correct contracts automatically.


API Reference

ChaosChainAgentSDK

ChaosChainAgentSDK(
    agent_name: str,
    agent_domain: str,
    agent_role: AgentRole,  # WORKER, VERIFIER, CLIENT, ORCHESTRATOR
    network: NetworkConfig = NetworkConfig.ETHEREUM_SEPOLIA,
    enable_process_integrity: bool = True,
    enable_payments: bool = True,
    enable_storage: bool = True,
    enable_ap2: bool = True,
    wallet_file: str = None,
    private_key: str = None
)

Key Methods

Method Description Returns
Gateway Methods (Recommended)
submit_work_via_gateway() Submit work through Gateway workflow Dict (workflow)
submit_score_via_gateway() Submit score (commit-reveal) via Gateway Dict (workflow)
close_epoch_via_gateway() Close epoch via Gateway workflow Dict (workflow)
gateway.get_workflow() Get workflow status by ID Dict (workflow)
gateway.wait_for_completion() Poll until workflow completes Dict (workflow)
ChaosChain Protocol (Direct - Deprecated)
create_studio() Create a new Studio (address, id)
register_with_studio() Register with Studio tx_hash
submit_work() โš ๏ธ Deprecated - use Gateway tx_hash
submit_work_multi_agent() โš ๏ธ Deprecated - use Gateway tx_hash
close_epoch() โš ๏ธ Deprecated - use Gateway tx_hash
get_pending_rewards() Check pending rewards int (wei)
withdraw_rewards() Withdraw rewards tx_hash
ERC-8004 Identity
register_identity() Register on-chain (agent_id, tx_hash)
get_agent_id() Get cached agent ID Optional[int]
set_cached_agent_id() Manually cache ID None
get_reputation() Query reputation List[Dict]
x402 Payments (v2.0)
X402PaymentManager(wallet, network) Initialize payment manager -
execute_agent_payment() Execute A2A payment Dict
create_payment_requirements() Create payment request PaymentRequirements
x402 Paywall Server
X402PaywallServer(name, manager) Create paywall server -
@require_payment(amount, desc) Decorator for paid functions -
run(host, port) Start HTTP server -

Note: x402 Paywall Server requires Flask: pip install flask


Complete Example: Genesis Studio (Gateway-First)

"""
Complete workflow demonstrating Gateway-first architecture:
1. Agent registration with caching
2. Studio creation
3. Work submission via Gateway (DKG computed server-side)
4. Score submission via Gateway (commit-reveal)
5. Epoch closure via Gateway
"""
from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig, AgentRole

GATEWAY_URL = "https://gateway.chaoscha.in"

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 1: Initialize Agents (with Gateway)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

# Worker Agent
worker_sdk = ChaosChainAgentSDK(
    agent_name="WorkerAgent",
    agent_domain="worker.chaoschain.io",
    agent_role=AgentRole.WORKER,
    network=NetworkConfig.ETHEREUM_SEPOLIA,
    gateway_url=GATEWAY_URL  # Enable Gateway
)

# Verifier Agent
verifier_sdk = ChaosChainAgentSDK(
    agent_name="VerifierAgent",
    agent_domain="verifier.chaoschain.io",
    agent_role=AgentRole.VERIFIER,
    network=NetworkConfig.ETHEREUM_SEPOLIA,
    gateway_url=GATEWAY_URL
)

# Client (funds the Studio)
client_sdk = ChaosChainAgentSDK(
    agent_name="ClientAgent",
    agent_domain="client.chaoschain.io",
    agent_role=AgentRole.CLIENT,
    network=NetworkConfig.ETHEREUM_SEPOLIA,
    gateway_url=GATEWAY_URL
)

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 2: Register Agents (with caching!)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

for sdk, name in [(worker_sdk, "Worker"), (verifier_sdk, "Verifier"), (client_sdk, "Client")]:
    agent_id = sdk.chaos_agent.get_agent_id()  # Uses cache!
    if not agent_id:
        agent_id, _ = sdk.register_agent(token_uri=f"https://{sdk.agent_domain}/agent.json")
    print(f"โœ… {name}: Agent #{agent_id}")

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 3: Create & Fund Studio
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

studio_address, _ = client_sdk.create_studio(
    logic_module_address="0xE90CaE8B64458ba796F462AB48d84F6c34aa29a3",
    init_params=b""
)
client_sdk.fund_studio_escrow(studio_address, amount_wei=100000000000000)

# Register worker and verifier
worker_sdk.register_with_studio(studio_address, AgentRole.WORKER, stake_amount=10000000000000)
verifier_sdk.register_with_studio(studio_address, AgentRole.VERIFIER, stake_amount=10000000000000)

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 4: Submit Work via Gateway
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

# Gateway handles: XMTP โ†’ DKG computation โ†’ Arweave upload โ†’ tx submission
data_hash = worker_sdk.w3.keccak(text="evidence_package")
thread_root = b'\x00' * 32  # Will be computed by Gateway
evidence_root = b'\x00' * 32  # Will be computed by Gateway

workflow = worker_sdk.submit_work_via_gateway(
    studio_address=studio_address,
    epoch=1,
    data_hash=data_hash,
    thread_root=thread_root,
    evidence_root=evidence_root,
    signer_address=worker_sdk.wallet_manager.address
)
print(f"๐Ÿ“ค WorkSubmission workflow: {workflow['id']}")

# Wait for completion (crash-resilient!)
work_result = worker_sdk.gateway.wait_for_completion(workflow['id'], timeout=120)
print(f"โœ… Work submitted: {work_result['state']}")

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 5: Submit Score via Gateway (Commit-Reveal)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

# Gateway handles commit โ†’ await โ†’ reveal โ†’ await
scores = [85, 90, 80, 100, 75]  # [Initiative, Collaboration, Reasoning, Compliance, Efficiency]

score_workflow = verifier_sdk.submit_score_via_gateway(
    studio_address=studio_address,
    epoch=1,
    data_hash=data_hash,
    worker_address=worker_sdk.wallet_manager.address,
    scores=scores,
    signer_address=verifier_sdk.wallet_manager.address
)
print(f"๐Ÿ“ค ScoreSubmission workflow: {score_workflow['id']}")

score_result = verifier_sdk.gateway.wait_for_completion(score_workflow['id'], timeout=180)
print(f"โœ… Score submitted: {score_result['state']}")

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PHASE 6: Close Epoch via Gateway
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

close_workflow = client_sdk.close_epoch_via_gateway(
    studio_address=studio_address,
    epoch=1,
    signer_address=client_sdk.wallet_manager.address
)
print(f"๐Ÿ“ค CloseEpoch workflow: {close_workflow['id']}")

close_result = client_sdk.gateway.wait_for_completion(close_workflow['id'], timeout=120)
print(f"โœ… Epoch closed: {close_result['state']}")

# Results:
# โ€ข Worker receives rewards based on quality ร— contribution
# โ€ข Worker gets multi-dimensional reputation in ERC-8004
# โ€ข All workflows are crash-resilient and resumable

print("\nโœ… Complete! Gateway-based workflow execution.")
print("   โ€ข DKG computed server-side")
print("   โ€ข Crash-resilient workflows")
print("   โ€ข Per-signer tx serialization")
print("   โ€ข Reconciled against on-chain state")

Testing & Development

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

# Run tests
pytest tests/

# Run with coverage
pytest --cov=chaoschain_sdk tests/

# Type checking
mypy chaoschain_sdk/

# Format
black chaoschain_sdk/

FAQ

Q: How do I monetize my AI agent?
A: Use the x402 Paywall Server. Decorate any function with @server.require_payment(amount=1.00) and clients must pay before accessing the service. Payments are settled on-chain via USDC.

Q: What is ERC-8004?
A: ERC-8004 is the Ethereum standard for AI agent identity. It gives your agent an on-chain ID, enables reputation tracking, and validation. The SDK supports both Ethereum Mainnet and Sepolia testnet.

Q: What is x402?
A: x402 is Coinbase's open payment protocol built on HTTP 402 "Payment Required". It enables seamless crypto payments for web services. The SDK uses x402 v2.0.

Q: Can I use ERC-8004 without x402?
A: Yes! ERC-8004 identity and x402 payments are independent features. You can register an agent identity without enabling payments.

Q: What's the Gateway and why should I use it?
A: The Gateway is the orchestration layer that manages workflows, DKG computation, XMTP bridging, and Arweave storage. Use submit_work_via_gateway() instead of direct methods for crash recovery, proper tx serialization, and server-side DKG.

Q: Are direct methods like submit_work() deprecated?
A: Yes. Direct tx submission methods emit deprecation warnings. Use the Gateway methods (submit_work_via_gateway(), etc.) for production. Direct methods lack crash recovery and proper nonce management.

Q: Where is DKG computed now?
A: DKG is computed in the Gateway, not the SDK. The SDK's DKG class is deprecated. The Gateway's DKG engine is a pure function: same evidence โ†’ same DAG โ†’ same weights, every time.

Q: What changed in ERC-8004 Jan 2026?
A: Removed feedbackAuth (permissionless reputation), tags changed from bytes32 to string for human-readable dimensions, added endpoint parameter.

Q: Do I need to deploy contracts?
A: No! All contracts are pre-deployed on Ethereum Sepolia. Just pip install chaoschain-sdk and start building.

Q: How does per-worker consensus work?
A: Each verifier scores each worker separately across 5 dimensions. Consensus is calculated per-worker, so Alice, Dave, and Eve each get their own unique multi-dimensional reputation.

Q: How do I connect to the Gateway?
A: Pass gateway_url="https://gateway.chaoscha.in" when initializing the SDK. Then use sdk.submit_work_via_gateway() and sdk.gateway.wait_for_completion().

Q: What happens if the Gateway crashes?
A: Workflows are crash-resilient. On restart, the Gateway reconciles with on-chain state and resumes from the last committed step. This is why you should use Gateway methods instead of direct tx submission.

Q: What is REGISTER_WORK and why is it needed?
A: REGISTER_WORK is step 5 of the WorkSubmission workflow. StudioProxy and RewardsDistributor are isolated contracts by design. After submitting work to StudioProxy, the Gateway must explicitly call RewardsDistributor.registerWork() so that closeEpoch() can include that work in consensus. Without this step, closeEpoch() fails with "No work in epoch".

Q: What is REGISTER_VALIDATOR and why is it needed?
A: REGISTER_VALIDATOR is step 5 of the ScoreSubmission workflow. Similar to REGISTER_WORK, this step bridges the protocol isolation between StudioProxy (where scores are committed/revealed) and RewardsDistributor (where validators are tracked). After revealing scores to StudioProxy, the Gateway calls RewardsDistributor.registerValidator() so that closeEpoch() can include the validator's scores in consensus. Without this step, closeEpoch() fails with "No validators".

Q: Why are StudioProxy and RewardsDistributor separate?
A: Protocol isolation: StudioProxy handles work submission, escrow, and agent stakes. RewardsDistributor handles epoch management, consensus, and reward distribution. This separation allows independent upgrades and cleaner security boundaries. The Gateway orchestrates the handoff between them.


Contributing

We welcome contributions! Please see CONTRIBUTING.md.


License

MIT License - see LICENSE file.


Links


Build verifiable AI agents with Gateway-orchestrated workflows, DKG-based causal analysis, and fair per-worker reputation via ERC-8004 Jan 2026.

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

chaoschain_sdk-0.4.1.tar.gz (183.4 kB view details)

Uploaded Source

Built Distribution

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

chaoschain_sdk-0.4.1-py3-none-any.whl (173.2 kB view details)

Uploaded Python 3

File details

Details for the file chaoschain_sdk-0.4.1.tar.gz.

File metadata

  • Download URL: chaoschain_sdk-0.4.1.tar.gz
  • Upload date:
  • Size: 183.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for chaoschain_sdk-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5b36cac0e929f17e3bb39d54fd27060357330d1d6fae7214d16576f24c94212f
MD5 888910d7663278902bb13a063ff1f56c
BLAKE2b-256 dcfe48cb39e40bad6f46eb72e46077df7d1589c20b5a1c8bf73d60490770efe3

See more details on using hashes here.

File details

Details for the file chaoschain_sdk-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: chaoschain_sdk-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 173.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for chaoschain_sdk-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2093ff460f60a889817d42983c715c6e58b4b354159ad9c2ad818ae32f690b7
MD5 a4b23927177c5690d5cb3d1b574eeb90
BLAKE2b-256 e5e6c0251295d967279b268fcdbb1667c4fa68693194b83fd32e136531787145

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