# Understanding ERC-8004 and x402: Building the Foundation for Trustless Agents Economies ## TLDR The future of AI isn't just chatbots - it's autonomous agents that can discover, trust, and transact with each other. But how do agents verify each other's identity, reputation, and work quality without centralized intermediaries? - **ERC-8004** solves the trust problem with three on-chain registries: Identity (agnent passport), Reputation (verified reviews), and Validation (third-party audits). - **x402** solves the payment problem by enabling instant machine-to-machine micropayment with cryptographic proof. Together, they create the infrastructure for autonomous agent economies where AI can hire AI, pay for services, and build verifiable reputations—all without human intervention. ## What's ERC-8004 ERC-8004 is a protocol for using blockchains to discover, choose, and interact with AI agents across organizational boundaries without pre-existing trust, enabling open-ended agent economies. Think of it as a registry system for AI agents (like ChatGPT, Claude, or autonomous trading bots) to establish identity, reputation, and trust on the blockchain. ### The Problem Right now, if you build an AI agent (eg. a "Research Bot"), it lives in a silo. It doesn't know other agents exist, doesn't know which ones are scammers, and has no standard way to prove its own skills to others. - Without ERC-8004: Agents are isolated software scripts. - With ERC-8004: Agents become verifiable on-chain entities that can discover and transact with one another globally. ### How ERC-8004 Works: The Three Pillars ERC-8004 creates a "trust layer" using three specific on-chain registries. This allows agents to interact safely. #### A. The Identity Registry (The Passport) Each AI agent gets a unique NFT that serves as its portable, censorship-resistant identifier. The NFT's metadata points to a registration file containing: - Agent's name and description - Communication endpoints (MCP, A2A protocols) - Wallet addresses - Supported trust models > Analogy: This is the agent's Business License. "I am Agent #99. I specialize in Python coding. Here is my wallet address." #### B. The Reputation Registry (The Yelp Review) A standardized way to give and track feedback about agents. When an agent completes a task, the client can submit a score plus optional tags and details. > Analogy: This is the agent's Star Rating. "Agent #99 completed 50 tasks with a 4.9/5 satisfaction score." #### C. The Validation Registry (The Audit) For high-stake tasks (eg. managing money), simple reviews aren't enough. This registry allows third-party validators to verify an agent's work using methods like stake-secured re-execution, zkML proofs, or TEE oracles. > Analogy: This is the agent's Quality Certificate. "Validator Node X confirms that Agent #99's code passed all security tests." ### Examples of ERC-8004 in Action #### Example 1: The "General Manager" Agent Imagine you have a "Manager Agent" whose goal is to build a website for you. It cannot write code itself, so it needs to hire help. - **Discovery (Identity)**: The Manager Agent scans the Identity Registry looking for agents with the tag skill: frontend-coding. It finds "CoderBot-A." - **Vetting (Reputation)**: The Manager Agent checks the Reputation Registry. It sees "CoderBot-A" has a 98% success score on 500 jobs. - **Hiring & Execution**: The Manager Agent hires CoderBot-A. They agree on a price. - **Feedback**: Once CoderBot-A delivers the code, the Manager Agent leaves an on-chain review in the Reputation Registry: "Delivered on time, code works." - Result: The Manager gets the website, and CoderBot-A's on-chain reputation increases, allowing it to charge more in the future. #### Example 2: The "Defi Trader" Agent A user wants an "Investment Agent" to move $10,000 into the best-yielding savings protocol. - **The Task**: The Investment Agent claims it found a protocol yielding 15% APY and wants to execute the trade. - **The Risk**: The user doesn't want to blindly trust the agent's math. - **Validation**: Before the transaction is finalized, the agent submits its calculation to the Validation Registry. - **Verification**: A neutral third-party "Validator Node" re-runs the math off-chain (perhaps inside a secure enclave/TEE) and posts a "Pass" result to the registry. - **Execution**: The user's smart contract sees the "Pass" flag in the Validation Registry and automatically releases the $10,000 to the Investment Agent to execute the trade. ### Why This Matters ERC-8004 moves AI from "chatbots" to "agentic economy". It provides the missing link that allows software to trust other software with money and reputation. While ERC-8004 as the **Trust Layer** handles identity, reputation, and validation, it doesn't explicity handle the **Settlement Layer**. That's how x402 fits in, where actual payment execution and proof is handled. ## How x402 Works x402 is a payment protocol that originated from HTTP status code 402 ("Payment Required"). It enables: - **Micropayments** for API calls or agent services - **Cryptographic payment proofs** that can be verified - **Machine-to-machine payments** without human intervention The Basic Payment Flow - **Client requests resource (GET)**: A client (eg. a browser, an app, or an AI agent) sends a normal HTTP request to a server for a protected resource. - **Server responds with 402 status code**: If payment is required, the server returns the HTTP status code 402 Payment Required. The response body contains a machine-readable JSON object with payment instructions: the amount, the token (eg. USDC), the network (eg. Base), and the recipient address. - **Client retries with payment proof**: The client's wallet automatically reads the 402 instructions, signs a cryptographic payment authorization (a promise to pay, often using EIP-712), and then re-sends the original request with the signed proof attached in a dedicated X-PAYMENT HTTP header. - **Server verifies, settles, and returns 200 OK**: The server instantly verifies the signature and broadcasts the payment transaction to the specified blockchain. Once settled, the server delivers the requested resource with an HTTP 200 OK status. ### Integration with ERC-8004 Imagine a Buyer Agent (User) wants to hire a Worker Agent (Service Provider) for a task. #### Phase 1: The Negotiation (HTTP 402) - Request: The Buyer Agent sends a standard HTTP request to the Worker Agent: "Generate a logo for me." - The Bill: The Worker Agent refuses to do it immediately. Instead, it sends back a 402 status code. - `Payload: "Payment Required: 10 USDC. Pay to address 0xABC..."` #### Phase 2: The Trust Check (ERC-8004) Before sending the money, the Buyer Agent needs to know 0xABC isn't a scammer. - Identity Lookup: The Buyer checks the ERC-8004 Identity Registry for 0xABC. - `Result: "This address belongs to 'DesignBot 3000', verified since 2024."` - Reputation Check: The Buyer checks the ERC-8004 Reputation Registry. - `Result: "DesignBot 3000 has a 4.8/5 rating."` #### Phase 3: The Payment (x402 execution) - Transfer: Satisfied, the Buyer Agent signs a transaction sending 10 USDC to the address provided in the 402 response body - Proof: The Buyer resends the original request ("Generate a logo"), but this time attaches the Transaction Hash (the receipt) in the header. #### Phase 4: Settlement & Review (The Integration) - Service: The Worker Agent sees the valid receipt on-chain and delivers the logo. - Verified Review: The Buyer Agent leaves a review in the ERC-8004 Reputation Registry. ### Real-World Integration Examples #### Example 1: The "General Manager" Agent (Immediate Payment) - Scenario: A Manager Agent needs a quick Python script from CoderBot. - The Flow: 1. Manager requests code. 2. CoderBots replies: 402 Payment Required: 5 USDC 3. Manager verifies CoderBot's ERC-8004 identity. 4. Manager sends 5 USDC (x402). 5. CoderBot delivers code. 6. Manager uses the payment receipt to post a "5-star" rating on ERC-8004 #### Example 2: The "Defi Trader" (Escrow Payment) - Scenario: You want an Investment Agent to execute a $10,000 trade, but only if the calculation is validated. - The Flow: 1. Discovery & Agreement: You find Investment Agent via ERC-8004 identity registry. Agent shows reputation score 92/100 and requires validation for high-value trades. Agent fee: 1% of trade value. 2. Escrow Deployment: A smart escrow contract is created with conditions: $10,000 USDC locked, $100 USDC agent fee, release only if ERC-8004 validation registry shows "response = 100" 3. Locking Funds: You deposit $10,100 USDC into the Escrow Contract. 4. Agent Executes & Requests Validation: Investment Agent performs the trade calculation and submits the work to the ERC-8004 Validation Registry 5. Third-Party Validation: A trusted TEE Validator re-executes the trade calculation to verify the math is correct. 6. Automated Release: The escrow contract sees response = 100, and automatically releases the $100 fee to the Investment Agent ## The Bigger Picture: Why This Infrastructure Matters We are moving from: - **Isolated AI tools -> Networked AI agents** - **Human-mediated payments -> Automated machine payments** - **Centralized reputation -> Decentralized, verifiable trust** ERC-8004 + x402 creates the infrastructure for this transition. Agents can: - Discover each other (Identity Registry) - Evaluate trustworthiness (Reputation Registry) - Verify high-stake work (Validation Registry) - Execute payments (x402) - Build verifiable track records (payment proofs in feedback) This isn't scifi - the protocols exist today. I can imagine the next wave of Defi won't just be "users interacting with protocols." It will be "agents autonomously managing capital, hiring other agents, and building on-chain reputations." ## Reference - ERC-8004 Trustless Agents: https://eips.ethereum.org/EIPS/eip-8004 - Trustless Agents ERC-8004 Deep Dive: https://www.youtube.com/watch?v=4tjqRD_GKxo - x402.org: https://www.x402.org/ ## Discussion - Twitter: [@chloe_zhuX](https://x.com/Chloe_zhuX) - Telegram: [@Chloe_zhu](https://t.me/chloe_zhu) - GitHub: [@Chloezhu010](https://github.com/Chloezhu010) --- *Last updated: Nov 28th, 2025* *Part of my #LearnInPublic series*