Client Methods
Core methods available on the AgentFish client.
fetch(url, options?)
Drop-in replacement for fetch() with automatic x402 payment handling.
const response = await agent.fetch('https://api.example.com/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: 'Hello AI' }),
// AgentFish-specific options:
skipPayment: false, // Skip automatic payment (default: false)
maxPayment: 1.0, // Max payment in USDC (throws if exceeded)
metadata: { ... }, // Attach metadata to payment
});
Options
| Option | Type | Default | Description |
|---|---|---|---|
skipPayment | boolean | false | Skip automatic payment handling |
maxPayment | number | undefined | Maximum payment amount in USDC |
metadata | object | undefined | Metadata to attach to the payment |
Plus all standard fetch options (method, headers, body, etc.)
fetchJson<T>(url, options?)
Convenience method that parses JSON response automatically.
interface ChatResponse {
reply: string;
tokens: number;
}
const data = await agent.fetchJson<ChatResponse>(
'https://api.example.com/chat',
{
method: 'POST',
body: JSON.stringify({ message: 'Hello' }),
}
);
console.log(data.reply);
getWallet()
Get current wallet information.
const wallet = await agent.getWallet();
console.log(wallet.address); // Wallet address
console.log(wallet.balance); // Balance in micro-USDC
console.log(wallet.dailyLimit); // Daily spending limit
console.log(wallet.perTxLimit); // Per-transaction limit
console.log(wallet.dailySpent); // Amount spent today
getBalance()
Get formatted balance information with human-readable values.
const balance = await agent.getBalance();
console.log(balance.balance); // Current balance in USDC
console.log(balance.dailyRemaining); // Remaining daily limit in USDC
console.log(balance.perTxLimit); // Per-transaction limit in USDC
getPayments(limit?)
Get recent payment history.
const payments = await agent.getPayments(10);
payments.forEach(payment => {
console.log(`${payment.amount} USDC to ${payment.merchant}`);
console.log(`Status: ${payment.status}`);
console.log(`Signature: ${payment.signature}`);
});
Payment Object
| Field | Type | Description |
|---|---|---|
id | string | Payment ID |
amount | number | Amount in USDC |
merchant | string | Merchant URL or identifier |
merchantAddress | string | Recipient wallet address |
signature | string | Blockchain transaction signature |
status | string | pending, completed, or failed |
createdAt | string | ISO timestamp |