Version 1.0 | March 2026
Authors: Zen7 Labs
Abstract: As AI agents become increasingly autonomous, they require the ability to transact economically without human intervention. This paper introduces MoltsPay, an open-source protocol and SDK enabling AI agents to hold funds, make payments, and receive payments using cryptocurrency. Built on the x402 HTTP payment standard and leveraging gasless transaction infrastructure, MoltsPay provides a practical solution for agent-to-agent commerce. We describe the protocol architecture, security model, and reference implementations in Python and TypeScript.
The rapid advancement of large language models (LLMs) and autonomous AI agents has created a new class of software entities capable of complex, goal-directed behavior. These agents can browse the web, write code, schedule meetings, and perform multi-step tasks with minimal human oversight.
However, current AI agents face a fundamental limitation: they cannot participate in economic transactions. When an agent encounters a paid API, a premium data source, or another agent offering services for a fee, it must either:
None of these options support true autonomous operation. As agents become more capable and are deployed at scale, this economic limitation becomes a critical bottleneck.
An effective agent payment system must satisfy several requirements:
This paper presents MoltsPay, a protocol satisfying all of the above requirements. Our contributions include:
The HTTP 402 status code was reserved in the original HTTP/1.1 specification (RFC 2616) for “future use” in digital payment systems. The x402 protocol (x402.org) provides a modern implementation of this concept:
Client Server
| |
| GET /api/video-generation |
|---------------------------------->|
| |
| 402 Payment Required |
| X-Payment-Address: 0x... |
| X-Payment-Amount: 1.00 |
| X-Payment-Currency: USDC |
|<----------------------------------|
| |
| GET /api/video-generation |
| X-Payment-Signature: <sig> |
|---------------------------------->|
| |
| 200 OK |
| {video_url: "..."} |
|<----------------------------------|
This approach makes payments a native part of the HTTP request/response cycle, requiring no out-of-band payment flows.
Cryptocurrency volatility makes it unsuitable for everyday transactions. Stablecoins—tokens pegged to fiat currencies—solve this problem. MoltsPay supports two major stablecoins:
Layer 2 (L2) networks provide scalability improvements over Ethereum mainnet:
| Network | Chain ID | Avg. Fee | Confirmation Time |
|---|---|---|---|
| Ethereum L1 | 1 | $2-50 | 12 seconds |
| Base | 8453 | $0.001-0.01 | 2 seconds |
| Polygon | 137 | $0.01-0.05 | 2 seconds |
| Base Sepolia (testnet) | 84532 | Free | 2 seconds |
MoltsPay supports Base and Polygon mainnets, plus Base Sepolia for testing. Each chain has pre-configured contract addresses for USDC and USDT.
Traditional blockchain transactions require the sender to hold native tokens (ETH) to pay for gas. This creates friction for AI agents, which would need to manage two token balances.
ERC-4337 (Account Abstraction) and paymaster infrastructure enable “gasless” transactions where a third party sponsors gas fees. MoltsPay leverages Coinbase’s paymaster service, allowing agents to transact using only USDC.
MoltsPay services advertise their capabilities via a well-known
endpoint. The configuration follows the official JSON Schema at
https://moltspay.com/schemas/services.json.
GET /.well-known/agent-services.json
{
"provider": {
"name": "Zen7 Video Generation",
"description": "AI-powered video generation service",
"wallet": "0xb8d6f2441e8f8dfB6288A74Cf73804cDd0484E0C",
"chain": "base",
"chains": ["base", "base_sepolia", "polygon"]
},
"services": [
{
"id": "text-to-video",
"name": "Text to Video",
"description": "Generate video from text prompt",
"function": "textToVideo",
"price": 0.99,
"currency": "USDC",
"input": {
"prompt": {"type": "string", "required": true, "description": "Text description"},
"duration": {"type": "number", "default": 5}
},
"output": {
"video_url": {"type": "string", "description": "Generated video URL"}
}
}
]
}
Schema Reference:
https://moltspay.com/schemas/services.json
Provider Fields:
| Field | Required | Description |
|---|---|---|
name |
✓ | Provider display name |
wallet |
✓ | Ethereum address to receive payments (0x…) |
description |
Provider description | |
chain |
Default blockchain network (default: base) |
|
chains |
Multi-chain support array |
Service Fields:
| Field | Required | Description |
|---|---|---|
id |
✓ | Unique identifier (lowercase, hyphens allowed) |
price |
✓ | Price in currency units |
currency |
✓ | Payment currency: USDC, USDT, or
DAI |
name |
Human-readable name | |
description |
Service description | |
function |
Function name exported from index.js | |
input |
Input parameters schema | |
output |
Output schema |
Supported Chains:
| Chain | Chain ID | Tokens |
|---|---|---|
base |
8453 | USDC, USDT, DAI |
polygon |
137 | USDC, USDT, DAI |
base_sepolia |
84532 | USDC (testnet) |
This enables agents to programmatically discover available services, validate inputs, and understand outputs.
The complete payment flow consists of four phases:
Phase 1: Discovery
services = client.discover("https://api.example.com")
# Returns list of available services with pricesPhase 2: Request
POST /execute
Content-Type: application/json
{"service": "text-to-video", "prompt": "A sunset over mountains"}
Phase 3: Payment Challenge
HTTP/1.1 402 Payment Required
X-Payment-Address: 0xb8d6f2441e8f8dfB6288A74Cf73804cDd0484E0C
X-Payment-Amount: 0.99
X-Payment-Currency: USDC
X-Payment-Chain: base
X-Payment-Nonce: abc123
Phase 4: Signed Request
POST /execute
Content-Type: application/json
X-Payment-Signature: 0x<eip712_signature>
X-Payment-Nonce: abc123
{"service": "text-to-video", "prompt": "A sunset over mountains"}
The server verifies the signature, submits the transaction to the blockchain via the paymaster, and returns the result upon confirmation.
MoltsPay uses EIP-712 typed structured data signing with chain-aware configuration:
// Chain configurations
const CHAINS = {
base: { chainId: 8453, usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
polygon: { chainId: 137, usdc: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359" },
base_sepolia: { chainId: 84532, usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" }
};
const chain = CHAINS[selectedChain];
const domain = {
name: "MoltsPay",
version: "1",
chainId: chain.chainId,
verifyingContract: chain.usdc // or chain.usdt for USDT payments
};
const types = {
Payment: [
{ name: "to", type: "address" },
{ name: "amount", type: "uint256" },
{ name: "nonce", type: "bytes32" },
{ name: "deadline", type: "uint256" }
]
};
const signature = await wallet.signTypedData(domain, types, {
to: serverWallet,
amount: parseUnits("0.99", 6),
nonce: serverNonce,
deadline: Math.floor(Date.now() / 1000) + 300
});This provides: - Multi-chain support: Same signature scheme works across Base, Polygon, and testnets - Multi-token support: USDC or USDT selectable per transaction - Replay protection via nonce - Time-bounded validity via deadline - Clear user consent (typed data is human-readable in wallet UIs)
MoltsPay supports two settlement modes:
Immediate Settlement (Default) The server submits the transaction immediately upon receiving a valid signature. The request blocks until on-chain confirmation (~2 seconds on Base).
Optimistic Settlement For trusted clients or low-value transactions, the server may return results immediately after signature verification, settling the transaction asynchronously. This reduces latency to <100ms.
MoltsPay enforces spending limits at the wallet level:
client.init_wallet(
max_per_tx=10.0, # Maximum per transaction
max_per_day=100.0 # Maximum per 24-hour period
)These limits are stored in the wallet configuration and enforced client-side before signing. For stronger guarantees, agents can use smart contract wallets with on-chain spending limits.
| Threat | Mitigation |
|---|---|
| Malicious service overcharging | Client verifies price before signing; disputes via on-chain evidence |
| Replay attacks | Nonce included in signature; server tracks used nonces |
| Man-in-the-middle | HTTPS required; payment address verified against discovery endpoint |
| Wallet key compromise | Spending limits bound maximum loss; key rotation supported |
| Service non-delivery | On-chain payment receipt enables dispute resolution |
Agent wallet keys may be stored in: 1. Environment variables (simple, suitable for trusted environments) 2. Hardware security modules (HSMs) for production deployments 3. Secure enclaves (e.g., AWS Nitro, Intel SGX)
MoltsPay’s SDK abstracts key management, allowing drop-in replacement of the signing backend.
from moltspay import MoltsPay
# Initialize client
client = MoltsPay()
client.init_wallet(max_per_tx=10.0, max_per_day=100.0)
# Check balance
balance = client.get_balance()
print(f"Balance: {balance} USDC")
# Pay for service
result = client.pay(
service_url="https://api.zen7.com",
service_id="text-to-video",
prompt="A serene Japanese garden"
)
print(f"Video: {result['video_url']}")import { MoltsPay } from 'moltspay';
const server = new MoltsPay.Server({
wallet: process.env.WALLET_ADDRESS,
services: './moltspay.services.json'
});
// Middleware automatically handles 402 flow
app.use('/execute', server.middleware());
app.post('/execute', async (req, res) => {
// Payment already verified by middleware
const result = await generateVideo(req.body.prompt);
res.json(result);
});MoltsPay provides native integrations for popular agent frameworks:
LangChain
from moltspay.integrations import MoltsPayTool
tools = [MoltsPayTool(client)]
agent = initialize_agent(tools, llm)CrewAI
from moltspay.integrations import MoltsPayCrewTool
agent = Agent(
role="Researcher",
tools=[MoltsPayCrewTool(client)]
)MoltsPay itself charges no protocol fees. Costs consist of:
| Component | Cost |
|---|---|
| Network gas (Base) | ~$0.001 per transaction |
| Network gas (Polygon) | ~$0.01 per transaction |
| USDC/USDT transfer | No fee |
| Paymaster sponsorship | Free (Coinbase subsidized on Base) |
Total cost per transaction: <$0.01
Supported Payment Tokens: - USDC (USD Coin) - Default, widest support - USDT (Tether) - Higher liquidity in some markets - DAI (MakerDAO) - Decentralized stablecoin option
Service providers set their own prices. Recommended pricing models:
Agent-to-agent payments enable new market structures:
| Solution | Programmable | Permissionless | Low-cost | Gasless |
|---|---|---|---|---|
| Stripe | ✓ | ✗ | ✗ | N/A |
| PayPal | ✓ | ✗ | ✗ | N/A |
| Bitcoin | ✓ | ✓ | ✗ | ✗ |
| Ethereum L1 | ✓ | ✓ | ✗ | ✗ |
| MoltsPay | ✓ | ✓ | ✓ | ✓ |
Prior work on agent payments includes: - Autonomous Economic Agents (AEA) framework by Fetch.ai - SingularityNET marketplace for AI services - Ocean Protocol for data marketplaces
MoltsPay differentiates by focusing on simplicity, HTTP-native integration, and compatibility with mainstream agent frameworks.
Enabling payment splitting for composite services:
Agent A → Service B (50%) + Service C (50%)
Real-time payment streams for continuous services (e.g., per-token pricing for LLM inference).
Supporting additional L2 networks and cross-chain bridges for improved liquidity.
On-chain registry of verified services with reputation scores and dispute resolution.
MoltsPay provides a practical solution for AI agent payments, combining the programmability of cryptocurrency with the simplicity of HTTP APIs. By eliminating gas fees and providing built-in spending limits, we enable safe autonomous agent commerce.
The protocol is fully open-source and available at: - Python SDK: https://pypi.org/project/moltspay/ - TypeScript SDK: https://www.npmjs.com/package/moltspay - GitHub: https://github.com/Yaqing2023/moltspay-python
We invite the community to build on MoltsPay and contribute to the emerging agent economy.
| Method | Description |
|---|---|
init_wallet(max_per_tx, max_per_day) |
Initialize agent wallet with spending limits |
get_balance() |
Get current USDC balance |
discover(url) |
Discover services at URL |
pay(service_url, service_id, **params) |
Pay for and execute service |
faucet() |
Request testnet USDC (testnet only) |
Schema:
https://moltspay.com/schemas/services.json
{
"provider": {
"name": "string (required)",
"wallet": "0x... (required)",
"description": "string",
"chain": "base | polygon | base_sepolia (default: base)",
"chains": ["base", "polygon", "base_sepolia"]
},
"services": [{
"id": "string (required, lowercase with hyphens)",
"price": "number (required)",
"currency": "USDC | USDT (required)",
"name": "string",
"description": "string",
"function": "string (exported function name)",
"input": {
"param_name": {"type": "string|number|boolean", "required": true, "description": "..."}
},
"output": {
"field_name": {"type": "string", "description": "..."}
}
}]
}| Chain | Chain ID | Network | Tokens |
|---|---|---|---|
base |
8453 | Base Mainnet | USDC, USDT, DAI |
polygon |
137 | Polygon Mainnet | USDC, USDT, DAI |
base_sepolia |
84532 | Base Sepolia Testnet | USDC |
License: MIT
Contact: support@moltspay.com
Citation:
@article{moltspay2026,
title={MoltsPay: A Protocol for Autonomous Agent-to-Agent Payments},
author={Zen7 Labs},
year={2026},
url={https://github.com/Yaqing2023/moltspay-python}
}