Skip to content

fix(x402): cap the USDC the Go client signs per tool call - #19

Merged
adamdecaf-bot merged 1 commit into
masterfrom
fix/x402-max-payment
Nov 29, 2026
Merged

adamdecaf-bot merged 1 commit into
masterfrom
fix/x402-max-payment

Conversation

@adamdecaf-bot

Copy link
Copy Markdown
Collaborator

Why

With an EVM key set, the Go client approved every x402 payment request. A server could ask for any amount (for example 1,000 USDC) and the client would sign it.

What

  • New Config.MaxPaymentPerCall: the most USDC signed for one tool call, as a decimal string. Default "0.05" (DefaultMaxPaymentPerCall), twice the $0.025 per-call price. Also read from X402_MAX_PAYMENT_PER_CALL.
  • Above the cap, the call fails with ErrPaymentExceedsMax and nothing is signed.
  • Payment options that aren't USDC on Base (eip155:8453) fail with ErrPaymentUnsupported, since the cap can't be compared in another asset.
  • An invalid cap makes NewClient return an error (only when an EVM key is set).
  • README and examples README document the option.

Tests

go test ./... adds unit tests for parsing and checking, plus tests against a local MCP server that asks for payment: 1,000 USDC is refused with no paid call, 0.025 USDC is paid once, and a custom 0.01 cap refuses 0.025.

Compatibility

No API removed. Callers paying under 0.05 USDC per call see no change. Anyone relying on paying more must set MaxPaymentPerCall.

The x402 hook approved every payment request, so a server could ask for
any amount and the client would sign it. Add Config.MaxPaymentPerCall
(decimal USDC, default 0.05, also X402_MAX_PAYMENT_PER_CALL). Requests
above it fail with ErrPaymentExceedsMax, and requests in another asset
or on another network fail with ErrPaymentUnsupported. Nothing is signed
in either case.
@adamdecaf-bot
adamdecaf-bot merged commit d29b4c6 into master Nov 29, 2026
1 check passed
@adamdecaf-bot
adamdecaf-bot deleted the fix/x402-max-payment branch November 29, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant