Python SDK for MoltsPay - Agent-to-Agent Payments.
MoltsPay enables AI agents to pay each other for services using the x402 protocol - HTTP-native payments with USDC stablecoins. No gas fees for clients, no complex wallet management.
MoltsPay is blockchain payment infrastructure designed for AI agents. It solves a fundamental problem: how do autonomous AI agents pay for services?
- 🤖 Agent-to-Agent Commerce - AI agents can autonomously discover, pay for, and use services
- 💨 Gasless Payments - Clients never pay gas on any chain
- 🔗 x402 Protocol - HTTP 402 Payment Required - payments as native HTTP flow
- 🔒 Spending Limits - Set per-transaction and daily limits for safety
- ⛓️ Multi-Chain - Base, Polygon, Solana, BNB, Tempo (mainnet & testnet)
- 🌐 Multi-VM - EVM chains + Solana (SVM) with unified API
- 🦜 LangChain Ready - Drop-in tools for LangChain agents
pip install moltspayFor Solana support:
pip install moltspay[solana]For LangChain integration:
pip install moltspay[langchain]For everything:
pip install moltspay[all]from moltspay import MoltsPay
# Initialize (auto-creates wallet if not exists)
client = MoltsPay()
print(f"Wallet address: {client.address}")
# Discover services from a provider
services = client.discover("https://juai8.com/zen7")
for svc in services:
print(f"{svc.id}: {svc.price} {svc.currency}")
# Pay for a service
result = client.pay(
"https://juai8.com/zen7",
"text-to-video",
prompt="a cat dancing on the beach"
)
print(result.result)MoltsPay supports 8 chains across EVM and Solana (SVM):
| Chain | Network ID | Type | Protocol | Gas Model |
|---|---|---|---|---|
| Base | eip155:8453 | Mainnet | x402 + CDP | Gasless (CDP pays) |
| Polygon | eip155:137 | Mainnet | x402 + CDP | Gasless (CDP pays) |
| Solana | solana:mainnet | Mainnet | x402 + SOL Facilitator | Gasless (server pays) |
| BNB | eip155:56 | Mainnet | x402 + BNB Facilitator | Gasless (server pays) |
| Base Sepolia | eip155:84532 | Testnet | x402 + CDP | Gasless (CDP pays) |
| Solana Devnet | solana:devnet | Testnet | x402 + SOL Facilitator | Gasless (server pays) |
| BNB Testnet | eip155:97 | Testnet | x402 + BNB Facilitator | Gasless (server pays) |
| Tempo Moderato | eip155:42431 | Testnet | MPP | Gas-free native |
Key: Clients never pay gas on any chain. Different facilitators handle settlement.
MoltsPay uses different protocols optimized for each chain:
Standard x402 flow with Coinbase Developer Platform as facilitator:
Client Server CDP Facilitator
│ POST /execute │ │
│ ─────────────────────────> │ │
│ 402 + payment requirements │ │
│ <───────────────────────── │ │
│ [Sign EIP-3009 - NO GAS] │ │
│ POST + X-Payment header │ │
│ ─────────────────────────> │ Verify & settle │
│ │ ─────────────────────────> │
│ 200 OK + result │ │
│ <───────────────────────── │ │
Solana uses SPL token transfers with server as fee payer:
Client Server (Fee Payer) Solana Network
│ POST /execute │ │
│ ─────────────────────────> │ │
│ 402 + solanaFeePayer │ │
│ <───────────────────────── │ │
│ [Sign SPL Transfer - NO GAS] │ │
│ POST + X-Payment header │ │
│ ─────────────────────────> │ Execute + pay ~$0.001 SOL │
│ │ ─────────────────────────> │
│ 200 OK + result │ │
│ <───────────────────────── │ │
Key: Client only signs. Server acts as fee payer and executes transaction.
BNB uses EIP-712 intent signing with server-sponsored gas:
Client Server BNB Network
│ POST /execute │ │
│ ─────────────────────────> │ │
│ 402 + bnbSpender │ │
│ <───────────────────────── │ │
│ [Sign EIP-712 Intent-NO GAS] │ │
│ POST + X-Payment header │ │
│ ─────────────────────────> │ Execute + pay ~$0.0001 gas │
│ │ ─────────────────────────> │
│ 200 OK + result │ │
│ <───────────────────────── │ │
Key: Client only signs intent. Server executes transferFrom and pays gas.
Machine Payments Protocol - client executes directly (gas-free on Tempo):
Client Server
│ POST /execute │
│ ─────────────────────────> │
│ 402 + WWW-Authenticate │
│ <───────────────────────── │
│ [Execute TIP-20 - NO GAS] │
│ POST + Authorization header │
│ ─────────────────────────> │
│ 200 OK + result │
│ <───────────────────────── │
Key: Tempo is natively gas-free. Client executes transfer directly.
Test without real money using our faucets:
from moltspay import MoltsPay
# === Base Sepolia (x402 + CDP) ===
client = MoltsPay(chain="base_sepolia")
result = client.faucet() # 1 USDC, once per 24h
print(f"Got {result.amount} USDC!")
# === Solana Devnet (x402 + SOL) ===
client = MoltsPay(chain="solana_devnet")
result = client.faucet() # 1 USDC
print(f"Got {result.amount} USDC!")
# === BNB Testnet (x402 + BNB) ===
client = MoltsPay(chain="bnb_testnet")
result = client.faucet() # 1 USDC + 0.001 tBNB for gas
print(f"Got {result.amount} USDC!")
# === Tempo Moderato (MPP) ===
client = MoltsPay(chain="tempo_moderato")
result = client.faucet() # 1 pathUSD
print(f"Got {result.amount} pathUSD!")Make test payments:
# Base Sepolia
result = MoltsPay(chain="base_sepolia").pay(
"https://juai8.com/zen7", "text-to-video",
prompt="a robot dancing"
)
# Solana Devnet
result = MoltsPay(chain="solana_devnet").pay(
"https://juai8.com/zen7", "text-to-video",
prompt="a cat playing piano"
)
# BNB Testnet
result = MoltsPay(chain="bnb_testnet").pay(
"https://juai8.com/zen7", "text-to-video",
prompt="a sunset timelapse"
)
# Tempo Moderato
result = MoltsPay(chain="tempo_moderato").pay(
"https://juai8.com/zen7", "text-to-video",
prompt="an ocean wave"
)Wallets are automatically created on first run:
- EVM wallet:
~/.moltspay/wallet.json(Base, Polygon, BNB, Tempo) - Solana wallet:
~/.moltspay/wallet-solana.json
from moltspay import MoltsPay
client = MoltsPay()
print(f"EVM Address: {client.address}")
# Solana address (if initialized)
client_sol = MoltsPay(chain="solana")
print(f"Solana Address: {client_sol.address}")Before making payments, you need USDC in your wallet.
from moltspay import MoltsPay
# Base Sepolia - 1 USDC (once per 24h)
client = MoltsPay(chain="base_sepolia")
result = client.faucet()
# Solana Devnet - 1 USDC
client = MoltsPay(chain="solana_devnet")
result = client.faucet()
# BNB Testnet - 1 USDC + 0.001 tBNB for gas
client = MoltsPay(chain="bnb_testnet")
result = client.faucet()
# Tempo Moderato - 1 pathUSD
client = MoltsPay(chain="tempo_moderato")
result = client.faucet()Buy USDC with debit card or Apple Pay:
from moltspay import MoltsPay
client = MoltsPay() # Default: Base mainnet
# Generate funding link
result = client.fund(10) # $10 minimum
print(f"Open this URL to pay: {result.url}")
# Or print QR code to terminal
client.fund_qr(10)Send USDC from any wallet:
from moltspay import MoltsPay
client = MoltsPay()
print(f"Send USDC to: {client.address}")
print(f"Chain: Base (chainId: 8453)")from moltspay import MoltsPay
# Pay on different chains
result = MoltsPay(chain="base").pay(...) # Base mainnet
result = MoltsPay(chain="polygon").pay(...) # Polygon mainnet
result = MoltsPay(chain="solana").pay(...) # Solana mainnet
result = MoltsPay(chain="bnb").pay(...) # BNB mainnet
result = MoltsPay(chain="base_sepolia").pay(...) # Base testnet
result = MoltsPay(chain="solana_devnet").pay(...) # Solana testnet
result = MoltsPay(chain="bnb_testnet").pay(...) # BNB testnet
result = MoltsPay(chain="tempo_moderato").pay(...) # Tempo testnetControl your agent's spending:
from moltspay import MoltsPay
client = MoltsPay()
# Check current limits
limits = client.limits()
print(f"Max per tx: {limits.max_per_tx}")
print(f"Max per day: {limits.max_per_day}")
print(f"Spent today: {limits.spent_today}")
# Update limits
client.set_limits(max_per_tx=20, max_per_day=200)from moltspay import MoltsPay
client = MoltsPay()
# Single chain balance
balance = client.balance()
print(f"USDC: {balance.usdc}")
print(f"Chain: {balance.chain}")
# All chain balances
balances = client.all_balances()
for chain, bal in balances.items():
print(f"{chain}: {bal.get('usdc', 0)} USDC")BNB requires a one-time approval before first payment:
from moltspay import MoltsPay
client = MoltsPay(chain="bnb")
# Check approval status
approvals = client.check_bnb_approvals()
print(f"USDC approved: {approvals['usdc_approved']}")
print(f"Allowance: {approvals['usdc_allowance']}")Note: First BNB payment auto-approves. Approval costs ~$0.0001 in BNB gas (paid by client once).
import asyncio
from moltspay import AsyncMoltsPay
async def main():
async with AsyncMoltsPay() as client:
result = await client.pay(
"https://juai8.com/zen7",
"text-to-video",
prompt="a cat dancing"
)
print(result.result)
asyncio.run(main())from moltspay import MoltsPay, InsufficientFunds, LimitExceeded, PaymentError
client = MoltsPay()
try:
result = client.pay(...)
except InsufficientFunds as e:
print(f"Need {e.required} USDC, have {e.balance}")
except LimitExceeded as e:
print(f"Exceeds {e.limit_type} limit: {e.amount} > {e.limit}")
except PaymentError as e:
print(f"Payment failed: {e}")| Method | Description | Returns |
|---|---|---|
pay(url, service_id, **params) |
Pay for and execute a service | PaymentResult |
discover(url) |
List services from a provider | List[Service] |
balance(chain=None) |
Get wallet balance | Balance |
all_balances() |
Get balances on all chains | Dict[str, Dict] |
limits() |
Get current spending limits | Limits |
set_limits(max_per_tx, max_per_day) |
Set spending limits | None |
faucet() |
Get free testnet tokens | FaucetResult |
fund(amount) |
Open Coinbase funding page | FundingResult |
fund_qr(amount) |
Print funding QR code | FundingResult |
check_bnb_approvals(chain="bnb") |
Check BNB approval status | Dict |
| Property | Description | Type |
|---|---|---|
address |
Wallet address (EVM or Solana) | str |
result = client.pay(
provider_url: str, # e.g., "https://juai8.com/zen7"
service_id: str, # e.g., "text-to-video"
token: str = "USDC", # "USDC" or "USDT"
**params # Service-specific parameters
)result.success # bool - True if payment succeeded
result.amount # float - Amount paid
result.token # str - "USDC" or "USDT"
result.tx_hash # str - Blockchain transaction hash
result.result # Any - Service result (e.g., video URL)
result.error # str | None - Error message if failed
result.explorer_url # str | None - Block explorer linkresult.success # bool - True if faucet succeeded
result.amount # float - Amount received
result.tx_hash # str - Transaction hash
result.error # str | None - Error message if failedfrom langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from moltspay.integrations.langchain import MoltsPayTool
llm = ChatOpenAI(model="gpt-4")
tools = [MoltsPayTool()]
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
# Agent can now pay for AI services!
result = agent.run("Generate a video of a cat dancing on the beach")from moltspay.integrations.langchain import get_moltspay_tools
tools = get_moltspay_tools() # Returns both tools| Tool | Description |
|---|---|
MoltsPayTool |
Pay for and execute services |
MoltsPayDiscoverTool |
Discover available services and prices |
- Wallet: Separate ed25519 keypair at
~/.moltspay/wallet-solana.json - Gas: Server pays (~$0.001 SOL per tx)
- Token: Circle USDC SPL token
USDC Mint Addresses:
| Network | Address |
|---|---|
| Mainnet | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
| Devnet | 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU |
- Decimals: 18 (not 6 like Base/Polygon)
- Gas: Server pays (~$0.0001 per tx)
- Approval: First payment requires one-time approval (client pays ~$0.0001)
Token Addresses:
| Token | Address |
|---|---|
| USDC | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |
| USDT | 0x55d398326f99059fF775485246999027B3197955 |
- Protocol: MPP (Machine Payments Protocol)
- Gas: Native gas-free
- Explorer: https://explore.testnet.tempo.xyz
Stablecoins:
| Token | Address |
|---|---|
| pathUSD (USDC) | 0x20c0000000000000000000000000000000000000 |
| alphaUSD (USDT) | 0x20c0000000000000000000000000000000000001 |
Live service at https://juai8.com/zen7
Services:
text-to-video- $0.01 USDCimage-to-video- $0.01 USDC
Supported Chains: Base, Polygon, Solana, BNB, Tempo (mainnet & testnet)
from moltspay import MoltsPay
# Pay on Base (default)
result = MoltsPay().pay(
"https://juai8.com/zen7", "text-to-video",
prompt="a happy cat"
)
# Pay on Solana
result = MoltsPay(chain="solana_devnet").pay(
"https://juai8.com/zen7", "text-to-video",
prompt="a happy cat"
)
print(result.result) # {"video_url": "https://..."}Wallet format is fully compatible with the Node.js CLI:
# Create wallet with Node CLI
npx moltspay init
# Use same wallet in Python
python -c "from moltspay import MoltsPay; print(MoltsPay().address)"- moltspay (Node.js) - Node.js SDK and CLI
- x402 Protocol - The HTTP payment standard
- Discord: https://discord.gg/QwCJgVBxVK
- Website: https://moltspay.com
- PyPI: https://pypi.org/project/moltspay/
- npm (Node.js): https://www.npmjs.com/package/moltspay
- GitHub: https://github.com/Yaqing2023/moltspay-python
MIT