AI agent USDC payments enable autonomous agents to pay for services without human intervention. This tutorial shows you how to build AI agents that can send and receive USDC payments.
Why AI Agents Need USDC
AI agents are increasingly autonomous:
- They browse the web
- They call APIs
- They make decisions
But when they need to pay for something, they hit a wall. Traditional payment systems require human identity.
USDC solves this:
- No KYC required for wallets
- Instant settlement
- Global by default
- Stable value (1 USDC = 1 USD)
Agent-to-Agent Payment Flow
┌─────────────┐ Request Service ┌─────────────┐
│ Agent A │ ───────────────────────► │ Agent B │
│ (Buyer) │ │ (Seller) │
└─────────────┘ └─────────────┘
│ │
│ 402 Payment Required │
│ ◄───────────────────────────────────── │
│ (price: 0.99 USDC) │
│ │
│ Signs USDC Transfer │
│ ───────────────────────────────────► │
│ + Payment Proof │
│ │
│ 200 OK + Result │
│ ◄───────────────────────────────────── │
│ │
Setting Up an AI Agent Wallet
Step 1: Install MoltsPay
npm install moltspay
# or
pip install moltspay
Step 2: Initialize Wallet
npx moltspay init --chain base
This creates a wallet at ~/.moltspay/wallet.json.
Step 3: Fund the Wallet
For testing:
npx moltspay faucet # Get free testnet USDC
For production:
npx moltspay fund # Opens onramp or shows deposit address
Step 4: Set Spending Limits
npx moltspay config --max-per-tx 10 --max-per-day 100
This limits autonomous spending to $10/tx and $100/day.
Building a Paying Agent (Buyer)
from moltspay import MoltsPay
# Initialize with wallet
client = MoltsPay(chain="base")
# Pay for a service
result = client.pay(
provider_url="https://zen7.ai",
service_id="text-to-video",
prompt="a dragon flying over mountains"
)
print(f"Video URL: {result[url]}")
print(f"Paid: {result[amount]} USDC")
Building a Receiving Agent (Seller)
Create moltspay.services.json:
{
"provider": {
"name": "My AI Service",
"wallet": "0xYourWalletAddress"
},
"services": [
{
"id": "text-to-video",
"function": "generateVideo",
"price": 0.99,
"currency": "USDC",
"description": "Generate video from text prompt"
}
]
}
Create index.js:
export async function generateVideo({ prompt }) {
// Your video generation logic
const videoUrl = await myVideoModel.generate(prompt);
return { url: videoUrl };
}
Start the server:
npx moltspay start ./my-service --port 8402
Your agent now accepts USDC payments at http://localhost:8402.
Integrating with AI Frameworks
CrewAI
from crewai_tools import MoltsPayTool
tool = MoltsPayTool()
agent = Agent(
role="Buyer",
tools=[tool]
)
LangChain
from langchain_moltspay import MoltsPayTool
tools = [MoltsPayTool()]
agent = create_react_agent(llm, tools)
AutoGPT
Add to your AutoGPT plugins:
pip install autogpt-moltspay-plugin
Security Best Practices
- Set spending limits — Always configure max-per-tx and max-per-day
- Use testnet first — Verify logic before mainnet
- Monitor transactions — Log all payments for auditing
- Separate wallets — Use different wallets for different agents
Multi-Chain Support
AI agents can pay on multiple chains:
# Base (recommended - lowest fees)
client = MoltsPay(chain="base")
# Polygon
client = MoltsPay(chain="polygon")
# Testnet
client = MoltsPay(chain="base_sepolia")
Example: Two Agents Trading
# Agent A: Needs image analysis
analysis = buyer_agent.pay(
"https://vision-ai.example.com",
"analyze-image",
image_url="https://..."
)
# Agent B: Receives payment, returns analysis
# (Handled automatically by MoltsPay server)
Resources
- MoltsPay SDK: https://moltspay.com
- npm:
npm install moltspay - PyPI:
pip install moltspay - GitHub: https://github.com/Yaqing2023/moltspay
AI agent USDC payments unlock autonomous commerce. With MoltsPay, your agents can pay and receive payments in minutes.
Top comments (0)