Give Your AI Agents a Wallet: MoltsPay + CrewAI in 10 Lines
Source: Dev.to
Introduction
Your CrewAI agents can research, write, and code. With MoltsPay you can also let them pay for AI services autonomously using crypto—in roughly 10 lines of code. This enables agents to purchase video generation, audio transcription, real‑time data, and other paid APIs without hard‑coding API keys or managing prepaid credits.
Install
pip install moltspayInitialize wallet
# Choose the blockchain (e.g., Base)
npx moltspay init --chain base
# Fund the wallet with USDC (or use a testnet)
npx moltspay fundExample with CrewAI
from crewai import Agent, Task, Crew
from crewai.tools import BaseTool
from moltspay import MoltsPay
class MoltsPayTool(BaseTool):
"""Pay for AI services (video, transcription, etc.) with USDC."""
name = "pay_service"
description = "Pay for AI services (video, transcription, etc.) with USDC"
def _run(self, provider: str, service: str, prompt: str) -> str:
client = MoltsPay()
return client.x402(f"{provider}/v1/{service}", data={"prompt": prompt})
# Agent equipped with the payment tool
creator = Agent(
role="Video Producer",
goal="Create engaging video content",
tools=[MoltsPayTool()],
)
# Task that triggers an autonomous payment
task = Task(
description="Generate a video of a cat dancing on a rainbow",
agent=creator,
)
crew = Crew(agents=[creator], tasks=[task])
result = crew.kickoff()When the task runs, the agent:
- Detects the need for video generation.
- Calls
MoltsPayTool(e.g., Zen7 video service). - MoltsPay receives a
402 Payment Required, signs a USDC payment, and retries. - The video URL is returned, and $0.99 USDC is transferred on‑chain (zero gas fees).
Alternative wrapper (LangChain)
from langchain.tools import BaseTool
from moltspay import MoltsPay
class MoltsPayTool(BaseTool):
name = "moltspay"
description = "Pay for AI services with USDC"
def _run(self, provider: str, service: str, prompt: str) -> str:
return MoltsPay().x402(f"{provider}/v1/{service}", data={"prompt": prompt})Simple usage without a framework
from moltspay import MoltsPay
client = MoltsPay()
video_url = client.x402(
"https://juai8.com/zen7/v1/text-to-video",
data={"prompt": "a dragon flying over mountains"},
)
print(f"Video ready: {video_url}")Spending limits
# Prevent runaway costs
npx moltspay config --max-per-tx 5 --max-per-day 50This caps each transaction at $5 and daily spending at $50.
Available services
| Service | Provider | Price |
|---|---|---|
| Text‑to‑Video | Zen7 | $0.99 |
| Image‑to‑Video | Zen7 | $1.49 |
| (more coming…) |
Future outlook
Agentic commerce—AI agents that can pay for compute, purchase data, and hire specialized services on‑demand—makes them fundamentally more capable. The x402 protocol is the “HTTP of payments,” and MoltsPay brings it to developers today.
Resources
- MoltsPay Docs
- x402 Protocol
- GitHub
- Discord
If you build something cool with MoltsPay, feel free to share a comment—I’d love to see it!