import { Agent } from 'openclaw'
import { Clawd402Tool } from '@clawd402/openclaw-plugin'
// Initialize Clawd402 payment tool
const paymentTool = new Clawd402Tool({
chains: ['base'],
walletPath: '~/.clawd402/wallet.json',
policiesPath: '~/.clawd402/policies.yaml'
})
// Create agent with payment capabilities
const agent = new Agent({
name: 'payment_agent',
tools: [paymentTool]
})
// Agent can now make payments via natural language
const result = await agent.run(`
Purchase access to weather API at https://api.weather.com/premium
for $5 USDC
`)
console.log(`Payment completed: ${result.paymentReceipt.txHash}`)
console.log(`Settled on: ${result.paymentReceipt.chain}`)
console.log(`Confirmation time: ${result.paymentReceipt.settlementTime}s`)
from openclaw import Agent
from clawd402 import Clawd402Provider
# Initialize payment provider
provider = Clawd402Provider(
chains=['base'],
wallet_path='~/.clawd402/wallet.json',
policies_path='~/.clawd402/policies.yaml'
)
# Create agent
agent = Agent(
name='payment_agent',
providers=[provider]
)
# Make payment
result = agent.run("""
Purchase access to weather API at https://api.weather.com/premium
for $5 USDC
""")
print(f"Payment hash: {result.tx_hash}")
print(f"Chain: {result.chain}")
print(f"Status: {result.status}")
// Configure agent to receive payments
const serviceTool = new Clawd402Tool({
chains: ['base'],
walletPath: '~/.clawd402/wallet.json',
receivePayments: true,
pricing: {
'data_analysis': 10, // $10 USDC per analysis
'code_review': 25, // $25 USDC per review
'report_generation': 50 // $50 USDC per report
}
})
const serviceAgent = new Agent({
name: 'data_analyst',
tools: [serviceTool]
})
// Offer service via x402
serviceAgent.serve()
// Agent now responds to HTTP requests with 402 Payment Required
// After payment received, executes service and returns results
// Agent subscribes to monthly data feed
const result = await agent.run(`
Subscribe to real-time market data at https://api.marketdata.com
for $50 USDC per month. Auto-renew if daily usage exceeds 80% of free tier.
`)
// Clawd402 handles:
// - Initial payment
// - Monthly renewal reminders
// - Automatic renewal (if within approval limits)
// - Cancellation if budget exceeded
const paymentTool = new Clawd402Tool({
chains: ['base', 'polygon', 'solana', 'stellar'],
preferredChain: 'base', // Primary
fallbackChains: ['polygon', 'solana', 'stellar'],
walletPath: '~/.clawd402/wallet.json'
})
// Agent will try Base first, fallback to Polygon if needed
// Solana used for micropayments (<$1) due to lower fees
// Stellar for cross-border payments
# Get testnet ETH for gas
curl -X POST https://faucet.base.org/api/claim \
-H "Content-Type: application/json" \
-d '{"address": "your-wallet-address"}'
# Get testnet USDC
# Visit: https://faucet.circle.com/