-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
Yaqing2023 edited this page Mar 7, 2026
·
1 revision
Complete reference for MoltsPay Python SDK.
Main synchronous client.
from moltspay import MoltsPayclient = MoltsPay(
chain: str = "base",
wallet_path: str = None,
max_per_tx: float = 10.0,
max_per_day: float = 100.0
)| Parameter | Type | Description | Default |
|---|---|---|---|
chain |
str | Blockchain to use | "base" |
wallet_path |
str | Path to wallet file | ~/.moltspay/wallet.json |
max_per_tx |
float | Max per transaction | 10.0 |
max_per_day |
float | Max per day | 100.0 |
Wallet address.
print(client.address) # 0xABC123...List available services from a provider.
services = client.discover("https://juai8.com/zen7")
for svc in services:
print(f"{svc.id}: {svc.price} {svc.currency}")Returns: List[Service]
Pay for and execute a service.
result = client.pay(
"https://juai8.com/zen7",
"text-to-video",
prompt="a cat dancing"
)
print(result.result)| Parameter | Type | Description |
|---|---|---|
url |
str | Provider URL |
service_id |
str | Service identifier |
**params |
Any | Service parameters |
Returns: PaymentResult
Get current USDC balance.
balance = client.balance()
print(f"{balance} USDC")Returns: float
Get spending 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}")Returns: Limits
Update spending limits.
client.set_limits(max_per_tx=20, max_per_day=200)Async version of the client.
from moltspay import AsyncMoltsPayimport asyncio
async def main():
async with AsyncMoltsPay() as client:
result = await client.pay(...)
asyncio.run(main())All methods are the same as MoltsPay but async:
await client.discover(url)await client.pay(url, service_id, **params)await client.balance()await client.limits()await client.set_limits(...)
@dataclass
class Service:
id: str
name: str
description: str
price: float
currency: str
input_schema: dict
output_schema: dict@dataclass
class PaymentResult:
success: bool
tx_hash: str
result: Any
error: str | None@dataclass
class Limits:
max_per_tx: float
max_per_day: float
spent_today: floatfrom moltspay import (
MoltsPayError,
InsufficientFunds,
LimitExceeded,
PaymentError
)Raised when wallet balance is too low.
try:
client.pay(...)
except InsufficientFunds as e:
print(f"Need {e.required} USDC, have {e.balance}")| Attribute | Type | Description |
|---|---|---|
required |
float | Amount needed |
balance |
float | Current balance |
Raised when spending limit is exceeded.
try:
client.pay(...)
except LimitExceeded as e:
print(f"Exceeds {e.limit_type} limit: {e.amount} > {e.limit}")| Attribute | Type | Description |
|---|---|---|
limit_type |
str | "per_tx" or "per_day" |
amount |
float | Attempted amount |
limit |
float | Current limit |
General payment failure.
try:
client.pay(...)
except PaymentError as e:
print(f"Payment failed: {e}")| Variable | Description |
|---|---|
MOLTSPAY_WALLET |
Custom wallet path |
MOLTSPAY_CHAIN |
Default chain |