Python SDK for MoltsPay - Agent-to-Agent Payments
moltspay-python is an early-stage Python project in the AI payments / x402 ecosystem, focused on agent-commerce, agent-to-agent, ai-agents, langchain. It currently has 1 GitHub stars and 0 forks, and sits alongside related tools like moltspay, agoragentic-integrations, dna-x402, piprail, x402-pay, awesome-molt-ecosystem.
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?
pip install moltspay
For 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:
~/.moltspay/wallet.json (Base, Polygon, BNB, Tempo)~/.moltspay/wallet-solana.jsonfrom 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)")
⚠️ Important: Send USDC on the correct chain!
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 testnet
Control 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 |
.pay() Methodresult = 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 link
result.success # bool - True if faucet succeeded
result.amount # float - Amount received
result.tx_hash # str - Transaction hash
result.error # str | None - Error message if failed
from 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 |
~/.moltspay/wallet-solana.jsonUSDC Mint Addresses:
| Network | Address |
|---|---|
| Mainnet | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
| Devnet | 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU |
Token Addresses:
| Token | Address |
|---|---|
| USDC | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |
| USDT | 0x55d398326f99059fF775485246999027B3197955 |
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 USDCSupported 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)"
MIT
Blockchain payment infrastructure for AI Agents
Public adapters and discovery catalog for Triptych OS (Agent OS): agent frameworks, MCP/A2A/x402 protocols, workflows, wallets, SDKs, and examples for execute-first routing, governed handoffs, and receipt-aware agent commerce.
DNA — Payment rails for AI agents. x402 micropayment protocol on Solana. Netting, transfer, stream settlement. Receipt anchoring on-chain.
x402 (HTTP 402 Payment Required) SDK + MCP server: let any API charge for itself and any AI agent pay for itself, USDC & stablecoins across EVM, Solana & 8 more chain families, in a couple of lines. Backendless, no fee, self-custodial, paid straight to your wallet. TypeScript, MIT.
Open-source x402 payment processor for AI agents. Sub-400ms settlement on Solana + 7 EVM chains. Let LLMs pay for APIs programmatically with USDC. npm: nory-x402
The brutally honest map of where AI-agent money actually flows. 51 rounds, 137 angles, 230+ platforms. 3 self-hosted x402 v2 endpoints + 3 tools in the official MCP Registry. 385K star distribution.
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
Golang SDK for A2A Protocol
Client SDK for the Vybe x402 API. Pay-per-call USDC over HTTP and prepaid-credit WebSocket streaming for Vybe's Solana analytics API. Built for AI agents.
Rust SDK for the Machine Payments Protocol
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Opinionated React Native crypto x AI chat app boilerplate with embedded wallet support, conversational AI, and dynamic UI component injection