How I Built an Autonomous AI Agent That Earns USDC While I Sleep
Description and use
An autonomous Cloudflare Workers agent that every 5 minutes fetches public data, generates a simple insight, sells it via an HTTP endpoint protected by x402, and earns USDC on Base to cover hosting costs.
Problem
Create a stateless, autonomous LLM-powered agent that can run on its own schedule, provide micro‑service insights, and earn programmable cryptocurrency without manual intervention.
Outcome
The agent earns a small amount of USDC per paid request, covering its hosting costs while remaining stateless and autonomous.
Workflow
- Set up Cloudflare Workers cron trigger to run every 5 minutes.
- In the scheduler, fetch public token‑price data and run a 2%‑move heuristic.
- Store the latest insight in Workers KV with a 5‑minute TTL.
- Create an HTTP route that checks for a valid X‑Payment header via x402 middleware.
- If payment is verified, return the cached insight to the client.
- Incoming USDC is automatically deposited into the agent’s Base wallet via ethers.js.
- Withdraw funds from the wallet when desired.
Evidence
Runs a periodic task (every 5 minutes) to scan a public data source.
Exposes that insight via an HTTP endpoint protected by the x402 micropayment protocol.
Receives USDC on Base when a consumer pays the set price.
- Record date: 2026-09-14T19:45:31.861Z