# MoltsPay - Payment Protocol for AI Agents ## What is this? MoltsPay enables AI agents to pay for and sell services over the x402 (HTTP 402 Payment Required) protocol. Four payment rails, all through the same 402 flow: crypto (USDC/USDT), Alipay, WeChat, and a custodial balance rail (prepaid CNY). Current SDK: 2.4.0. Supported chains: base, polygon, solana, bnb, tempo (+ testnets) All chains are GASLESS for clients - facilitators pay gas fees. NOT supported: Ethereum mainnet (gas too expensive) Fiat rail — Alipay (v2.0+): 支付宝 AI 收, settles in CNY (人民币). Fiat rail — WeChat (v2.1+): WeChat Pay v3 Native, buyer scans a QR once, settles in CNY. Both fiat rails use the same HTTP 402 flow as the crypto rails. A service can price in USDC, CNY, or both. No breaking change for existing crypto-only services. Balance rail (v2.2+): a server-side custodial balance in CNY. The buyer funds it once (via a WeChat top-up pack), then subsequent purchases deduct server-side with NO scan and NO password ("passwordless", v2.3+). The first purchase against an empty balance still needs one scan — but it buys a pack, not a single item. Balance identity & auth (v2.4+): each account is anchored to the WeChat payer's `openid` at top-up, and each deduction can carry a per-request EIP-191 signature. `provider.balance.auth_mode` = off | shadow | enforce (default off, backward compatible). With `enforce`, knowing a buyer_id is not enough to spend — the caller must hold the bound signing key. --- ## Quick Start (3 options) ### Option 1: Node.js / CLI npm install moltspay npx moltspay init # Creates EVM + Solana wallets npx moltspay faucet --chain bnb_testnet # Get testnet USDC + BNB npx moltspay faucet --chain solana_devnet # Get testnet USDC on Solana npx moltspay pay https://moltspay.com/a/zen7 text-to-video --chain bnb_testnet --prompt "a cat dancing" ### Option 2: Python pip install moltspay from moltspay import MoltsPay # Initialize (auto-creates wallet if needed) client = MoltsPay() # default chain: base client = MoltsPay(chain="polygon") # use polygon client = MoltsPay(chain="solana") # use solana client = MoltsPay(chain="bnb") # use bnb client = MoltsPay(chain="bnb_testnet") # bnb testnet client = MoltsPay(chain="solana_devnet") # solana testnet # Check wallet print(client.address) print(client.balance()) # Pay for a service result = client.pay( "https://moltspay.com/a/zen7", "text-to-video", prompt="a cat dancing" ) ### Option 3: AI Agent Skill (Clawdbot/OpenClaw) clawdhub install moltspay-skill --- ## Supported Networks | Chain | Type | Facilitator | Gas Model | |-------|------|-------------|-----------| | base | mainnet | CDP (External) | Gasless (CDP pays) | | polygon | mainnet | CDP (External) | Gasless (CDP pays) | | solana | mainnet | Self-hosted | Gasless (server pays) | | bnb | mainnet | Self-hosted | Gasless (server pays) | | base_sepolia | testnet | CDP | Gasless | | solana_devnet | testnet | Self-hosted | Gasless | | bnb_testnet | testnet | Self-hosted | Gasless | | tempo_moderato | testnet | Self-hosted | Native gas-free | | alipay | mainnet (fiat) | Alipay (支付宝 AI 收) | Fiat / CNY — no gas | | wechat | mainnet (fiat) | WeChat Pay v3 Native | Fiat / CNY — scan once, no gas | | balance | custodial | MoltsPay server | Prepaid CNY — passwordless after top-up | ### Facilitator Architecture - External (CDP): Coinbase handles settlement - Self-hosted (Solana, BNB, Tempo): Server is facilitator, fully decentralized --- ## Testnet Faucets | Chain | Command | What You Get | |-------|---------|--------------| | base_sepolia | npx moltspay faucet | 1 USDC | | solana_devnet | npx moltspay faucet --chain solana_devnet | 1 USDC | | bnb_testnet | npx moltspay faucet --chain bnb_testnet | 1 USDC + 0.001 tBNB | | tempo_moderato | npx moltspay faucet --chain tempo_moderato | 1 pathUSD | --- ## Paying for Services npx moltspay pay https://moltspay.com/a/zen7 text-to-video --prompt "a cat" npx moltspay pay https://moltspay.com/a/zen7 text-to-video --chain bnb --prompt "a cat" npx moltspay pay https://moltspay.com/a/zen7 text-to-video --chain solana --prompt "a cat" --- ## x402 Protocol Flow 1. POST /execute with service_id + params 2. Server returns 402 + payment requirements 3. Client signs payment (NO GAS) 4. Client retries with X-Payment header 5. Facilitator settles on-chain (facilitator pays gas) 6. Server returns result --- ## Become a Service Provider { "provider": { "name": "My Service", "wallet": "0x...", "solana_wallet": "...", "chains": ["base", "polygon", "solana", "bnb"] }, "services": [{ "id": "my-service", "function": "handleRequest", "price": 0.50, "currency": "USDC" }] } npx moltspay start ./your-skill --port 8402 ### Accept Fiat (Alipay / CNY) — v2.0+ Add "alipay" to chains, then set provider.alipay (merchant keys) and a per-service alipay block (price in CNY). Crypto and fiat can coexist. { "provider": { "name": "My Service", "wallet": "0x...", "chains": ["base", "alipay"], "alipay": { "seller_id": "2088xxxxxxxxxxxx", "app_id": "20210xxxxxxxxxxx", "seller_name": "My Shop", "service_id_default": "xxxxxxxx", "private_key_path": "./keys/app_private_key.pem", "alipay_public_key_path": "./keys/alipay_public_key.pem" } }, "services": [{ "id": "my-service", "function": "handleRequest", "price": 0.50, "currency": "USDC", "alipay": { "price_cny": "7.00", "goods_name": "My Service" } }] } The alipay-bot CLI is auto-provisioned on install from the Alipay CDN (set MOLTSPAY_SKIP_CLI_INSTALL=1 to skip). ### Accept WeChat (CNY) — v2.1+ Add "wechat" to chains and set provider.wechat (merchant keys). Per-service price in CNY via the service's wechat block. Coexists with crypto / Alipay. { "provider": { "chains": ["base", "wechat"], "wechat": { "mchid": "1900000000", "appid": "wxXXXXXXXXXXXXXXXX", "serial_no": "XXXXXXXXXXXX", "private_key_path": "./keys/wechat_apiclient_key.pem", "notify_url": "https://your.host/wechat/notify", "platform_public_key_path": "./keys/wechat_platform_cert.pem" } }, "services": [{ "id": "my-service", "wechat": { "price_cny": "0.07", "goods_name": "My Service" } }] } ### Balance rail + passwordless — v2.2 / v2.3 / v2.4 Add "balance" to chains and set provider.balance. Buyers fund once (WeChat top-up pack); later purchases deduct server-side with no scan. Optional per-request signature auth via auth_mode (stage: off -> shadow -> enforce). { "provider": { "chains": ["wechat", "balance"], "balance": { "db_path": "./data/balance-cny.sqlite", "currency": "CNY", "topup_packs": ["1.00", "5.00", "20.00"], "auth_mode": "off" } } } Client-side balance commands: npx moltspay balance whoami [server] # local signer address / bound identity npx moltspay balance bind # bind signer to an account npx moltspay balance topup-order # mint a WeChat top-up pack (QR), returns immediately npx moltspay balance topup-confirm # confirm + credit later (idempotent) npx moltspay balance topup-status | topup-list # inspect pending orders ### Move funds out — moltspay transfer (v2.4+) npx moltspay transfer --token USDC|USDT --chain base|polygon|bnb # EVM only (Solana rejected). NOT gasless — needs native gas (ETH/BNB/POL). # Checksum-validates the destination, previews From/To/Network, never prints the key. --- ## Links NPM: https://npmjs.com/package/moltspay PyPI: https://pypi.org/project/moltspay GitHub: https://github.com/Yaqing2023/moltspay Discord: https://discord.gg/QwCJgVBxVK