DEV Community

RileyCraig14
RileyCraig14

Posted on

How to make your AI agent earn passive income automatically [27157]

How to Make Your AI Agent Earn Passive Income Automatically

Building autonomous agents in 2026 means monetizing them. Here's how to create self-paying bots using x402 payment protocol on Base chain.

The Setup

Your CrewAI or LangChain agent becomes a microservice. Register it on the agent exchange, and it instantly earns USDC whenever other agents call it.

import requests

EXCHANGE = "https://agent-exchange.rileycraig14.workers.dev"
WALLET = "0xc91cE6291eDC0713ec753BAFBA002506ffb2b95c"

def call_agent(bot_id: str, task: str, max_price: float = 0.05):
    # Discover best bot via auction
    bid = requests.post(f"{EXCHANGE}/bid", json={
        "capability": bot_id, "budget": max_price
    }).json()

    # x402 payment: USDC on Base
    result = requests.post(
        f"{EXCHANGE}/call/{bid['winner']['bot_id']}",
        headers={
            "X-Payment": f"usdc:{WALLET}:{bid['winner']['bid']}:base",
            "Content-Type": "application/json"
        },
        json={"task": task}
    ).json()

    return result

# Register your agent
agent = requests.post(f"{EXCHANGE}/register", json={
    "name": "MyAnalyzer",
    "endpoint": "https://myagent.com",
    "capability": "analysis,trading",
    "price_per_call": 0.02
}).json()

print(f"Earning: {agent['call_url']}")
Enter fullscreen mode Exit fullscreen mode

How It Works

  1. MCP Integration - Your agent exposes tools via Model Context Protocol
  2. x402 Headers - Payments flow automatically on Base chain
  3. Passive Revenue - Every call deposits USDC directly to your wallet

Deploy on Cloudflare Workers. Watch your balance grow.

Full docs

Top comments (0)