x402_balance
Check your AgentCash USDC wallet balance on Base to see available funds for x402 payments and estimate how many calls you can make. If not set up, get instructions to create and fund a wallet.
Instructions
Check your AgentCash USDC wallet balance on Base.
Returns current balance available for x402 payments and approximate number of calls you can afford. No parameters required.
If AgentCash is not set up, provides instructions to create and fund a wallet.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- cli.js:424-437 (schema)Tool definition and input schema for x402_balance. Defines the tool name, description, and empty inputSchema (no parameters required).
{ name: 'x402_balance', description: `Check your AgentCash USDC wallet balance on Base. Returns current balance available for x402 payments and approximate number of calls you can afford. No parameters required. If AgentCash is not set up, provides instructions to create and fund a wallet.`, inputSchema: { type: 'object', properties: {}, required: [], }, }, - cli.js:534-557 (handler)Handler function handleBalance() that executes the x402_balance tool logic. Calls getBalance() which invokes 'agentcash balance --format json', formats the response showing USDC balance and estimated number of calls.
async function handleBalance() { const result = await getBalance(); if (!result.success) { return { content: [{ type: 'text', text: `Could not check balance: ${result.error}\n\nTo set up AgentCash:\n1. Run: npx agentcash install\n2. Fund at https://agentcash.dev/deposit`, }], isError: true, }; } const balance = result.data.balance ?? result.data.raw ?? 'unknown'; const numBalance = Number(balance); const callEstimate = isNaN(numBalance) ? '?' : Math.floor(numBalance / 0.12); return { content: [{ type: 'text', text: `AgentCash balance: $${balance} USDC on Base\nApproximately ${callEstimate} calls at $0.12/call.`, }], }; } - cli.js:355-357 (helper)getBalance() helper function that wraps agentcashExec to call 'agentcash balance --format json' and parse the result.
async function getBalance() { return agentcashExec('balance --format json'); } - cli.js:678-696 (registration)Registration of the x402_balance tool in the MCP server's CallToolRequestSchema handler. Routes the tool name 'x402_balance' to the handleBalance() function.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; switch (name) { case 'x402_discover': return handleDiscover(args); case 'x402_call': return handleCall(args); case 'x402_balance': return handleBalance(); case 'x402_research': return handleResearch(args); default: return { content: [{ type: 'text', text: `Unknown tool: ${name}. Available: x402_discover, x402_call, x402_balance, x402_research` }], isError: true, }; } });