Skip to main content

Python SDK for ERC-8004 Trustless Agents protocol

Project description

ERC-8004 SDK (Python)

Python SDK for interacting with ERC-8004 Trustless Agents protocol.

Installation

pip install erc-8004-py

Quick Start

from erc8004 import ERC8004Client, Web3Adapter
from web3 import Web3

# Connect to Ethereum node
w3 = Web3(Web3.HTTPProvider('YOUR_RPC_URL'))
adapter = Web3Adapter(w3, private_key='0x...')

# Initialize client
client = ERC8004Client(
    adapter=adapter,
    addresses={
        'identityRegistry': '0x...',
        'reputationRegistry': '0x...',
        'validationRegistry': '0x...',
        'chainId': 11155111,
    }
)

# Register an agent
result = client.identity.register_with_uri('ipfs://QmYourAgentData')
print(f"Agent ID: {result['agentId']}")

Contract Addresses

Sepolia Testnet

addresses = {
    'identityRegistry': '0x8004a6090Cd10A7288092483047B097295Fb8847',
    'reputationRegistry': '0x8004B8FD1A363aa02fDC07635C0c5F94f6Af5B7E',
    'validationRegistry': '0x8004CB39f29c09145F24Ad9dDe2A108C1A2cdfC5',
    'chainId': 11155111,
}

Core Features

Identity Management

# Register an agent
result = client.identity.register_with_uri('ipfs://QmYourAgentData')
agent_id = result['agentId']

# Get agent info
owner = client.identity.get_owner(agent_id)
token_uri = client.identity.get_token_uri(agent_id)

Reputation & Feedback

import time

# Create feedback authorization (agent owner signs)
feedback_auth = client.reputation.create_feedback_auth(
    agent_id,
    client_address,
    index_limit,
    int(time.time()) + 3600,
    chain_id,
    signer_address
)

signed_auth = client.reputation.sign_feedback_auth(feedback_auth)

# Submit feedback
client.reputation.give_feedback(
    agent_id=agent_id,
    score=95,
    tag1='excellent-service',
    tag2='fast-response',
    feedback_auth=signed_auth,
)

# Get reputation summary
summary = client.reputation.get_summary(agent_id)

Validation

from erc8004 import ipfs_uri_to_bytes32

# Request validation
request_uri = 'ipfs://QmValidationRequest'
request_hash = ipfs_uri_to_bytes32(request_uri)

client.validation.validation_request(
    validator_address=validator_address,
    agent_id=agent_id,
    request_uri=request_uri,
    request_hash=request_hash,
)

# Validator provides response
client.validation.validation_response(
    request_hash=request_hash,
    response=100,
    response_uri='ipfs://QmValidationResponse',
    tag='zkML-proof',
)

IPFS Integration

from erc8004 import IPFSClientConfig, create_ipfs_client, cid_to_bytes32

# Create IPFS client
config = IPFSClientConfig(
    provider='pinata',
    api_key='YOUR_PINATA_API_KEY',
    api_secret='YOUR_PINATA_API_SECRET',
)
ipfs = create_ipfs_client(config)

# Upload agent registration data
agent_data = {
    'type': 'https://eips.ethereum.org/EIPS/eip-8004#registration-v1',
    'name': 'My Agent',
    'description': 'AI agent for task automation',
    'endpoints': [],
}

result = ipfs.upload_json(agent_data)
client.identity.register_with_uri(result.uri)

# Convert CID to bytes32
hash_bytes = cid_to_bytes32(result.cid)

API Reference

ERC8004Client

Main client with three sub-clients:

  • client.identity - Agent registration and identity
  • client.reputation - Feedback and reputation
  • client.validation - Validation requests and responses

IdentityClient

  • register() - Register agent without URI
  • register_with_uri(uri) - Register with token URI
  • register_with_metadata(uri, metadata) - Register with URI and metadata
  • get_token_uri(agent_id) - Get token URI
  • get_owner(agent_id) - Get agent owner
  • get_metadata(agent_id, key) - Get on-chain metadata
  • set_metadata(agent_id, key, value) - Set on-chain metadata

ReputationClient

  • create_feedback_auth(...) - Create feedback authorization
  • sign_feedback_auth(auth) - Sign feedback authorization
  • give_feedback(...) - Submit feedback
  • revoke_feedback(agent_id, index) - Revoke feedback
  • get_summary(agent_id, ...) - Get reputation summary
  • read_feedback(agent_id, client, index) - Read specific feedback
  • get_clients(agent_id) - Get all clients who gave feedback
  • get_last_index(agent_id, client) - Get last feedback index

ValidationClient

  • validation_request(...) - Request validation
  • validation_response(...) - Provide validation response
  • get_validation_status(request_hash) - Get validation status
  • get_summary(agent_id, ...) - Get validation summary
  • get_agent_validations(agent_id) - Get all validations for agent

IPFSClient

  • upload(content, name, metadata) - Upload content
  • upload_json(data, name, metadata) - Upload JSON
  • pin(cid, name) - Pin existing CID
  • fetch(cid_or_uri) - Fetch content
  • fetch_json(cid_or_uri) - Fetch and parse JSON

Links

License

MIT

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

erc_8004_py-0.1.3.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

erc_8004_py-0.1.3-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file erc_8004_py-0.1.3.tar.gz.

File metadata

  • Download URL: erc_8004_py-0.1.3.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for erc_8004_py-0.1.3.tar.gz
Algorithm Hash digest
SHA256 41346aad8ec630436d492059ad9e76df3c408ffa8c7e59f22e9a253119f5beb1
MD5 547f15acdc441a0f450880420214dbab
BLAKE2b-256 bbfd8d077546624e61793c2ac7f79e82b8a72cf4cf63a38009e9f5fac88206ae

See more details on using hashes here.

File details

Details for the file erc_8004_py-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: erc_8004_py-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for erc_8004_py-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 93078aeed6d0ea56236dd135b39a7ed2188fde3e75fb033da85ba987c94bb7bb
MD5 b9a996bc130233093eb0299b600aba65
BLAKE2b-256 5d5aeff778793ac79fdc07ffcc6d8f974190b5a12fced6062e4df5de4dd71dab

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