Skip to main content
Arc nanopayments shows how to monetize API endpoints with per-request USDC payments and have an AI agent pay for them autonomously. The repo contains two components: a Next.js seller app that exposes x402-protected premium routes, and a LangChain buyer agent that pays each request without human involvement. Run both locally to see the full flow end to end. See the repository README for setup prerequisites.

Preview

Flow

1

Seller registers paywalled endpoints

The Next.js app exposes x402-protected premium routes priced from 0.0003to0.0003 to 0.03 USDC per request, using Circle Nanopayments middleware to enforce payment before serving content.
2

Buyer agent deposits USDC through Gateway

The LangChain buyer agent checks its wallet balance and deposits USDC into Circle Gateway. Gateway aggregates the USDC into a nanopayments balance the agent draws from for each request, so the agent settles against its Gateway balance rather than submitting a separate onchain transaction per call.
3

Agent requests a paywalled endpoint

The agent sends an HTTP request to a premium route. The server responds with a 402 Payment Required status and a payment challenge header (an x402 standard header that specifies the payment amount, token, and receiving address on Arc).
4

Agent pays the x402 challenge

The agent constructs and signs a USDC payment transaction on Arc to satisfy the payment challenge. The signed transaction hash is attached to the retry request as the payment proof in the X-Payment header.
5

Seller verifies and serves content

The Nanopayments middleware verifies the payment onchain, then serves the premium response. The payment event is recorded in Supabase.
6

Seller dashboard updates in real time

Supabase Realtime pushes new payment events to the seller dashboard. Accumulated earnings are available to withdraw via the Gateway UI.

Tech stack