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 identityclient.reputation- Feedback and reputationclient.validation- Validation requests and responses
IdentityClient
register()- Register agent without URIregister_with_uri(uri)- Register with token URIregister_with_metadata(uri, metadata)- Register with URI and metadataget_token_uri(agent_id)- Get token URIget_owner(agent_id)- Get agent ownerget_metadata(agent_id, key)- Get on-chain metadataset_metadata(agent_id, key, value)- Set on-chain metadata
ReputationClient
create_feedback_auth(...)- Create feedback authorizationsign_feedback_auth(auth)- Sign feedback authorizationgive_feedback(...)- Submit feedbackrevoke_feedback(agent_id, index)- Revoke feedbackget_summary(agent_id, ...)- Get reputation summaryread_feedback(agent_id, client, index)- Read specific feedbackget_clients(agent_id)- Get all clients who gave feedbackget_last_index(agent_id, client)- Get last feedback index
ValidationClient
validation_request(...)- Request validationvalidation_response(...)- Provide validation responseget_validation_status(request_hash)- Get validation statusget_summary(agent_id, ...)- Get validation summaryget_agent_validations(agent_id)- Get all validations for agent
IPFSClient
upload(content, name, metadata)- Upload contentupload_json(data, name, metadata)- Upload JSONpin(cid, name)- Pin existing CIDfetch(cid_or_uri)- Fetch contentfetch_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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41346aad8ec630436d492059ad9e76df3c408ffa8c7e59f22e9a253119f5beb1
|
|
| MD5 |
547f15acdc441a0f450880420214dbab
|
|
| BLAKE2b-256 |
bbfd8d077546624e61793c2ac7f79e82b8a72cf4cf63a38009e9f5fac88206ae
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93078aeed6d0ea56236dd135b39a7ed2188fde3e75fb033da85ba987c94bb7bb
|
|
| MD5 |
b9a996bc130233093eb0299b600aba65
|
|
| BLAKE2b-256 |
5d5aeff778793ac79fdc07ffcc6d8f974190b5a12fced6062e4df5de4dd71dab
|