Skip to content

feat(sdk): initX402({ maxAmountPerPayment }) to raise the x402 per-payment cap - #130

Merged
Eras256 merged 1 commit into
nirium-protocol:mainfrom
Edgadafi:feat/configurable-x402-cap
Oct 13, 2026
Merged

Eras256 merged 1 commit into
nirium-protocol:mainfrom
Edgadafi:feat/configurable-x402-cap

Conversation

@Edgadafi

Copy link
Copy Markdown
Contributor

Closes #106

What

initX402() now accepts an optional maxAmountPerPayment, passed to @x402/core as spendControls.maxAmountPerPayment, so APIs priced above $1 can be paid with Nirium.

Checked against @x402/core 2.28.0 (installed, not older docs)

  • x402Client.setSpendControls(controls); SpendControls.maxAmountPerPayment?: Money | false, default DEFAULT_MAX_AMOUNT_PER_PAYMENT = "$1".
  • Enforced in applySpendControls, before the payload is created, so a blocked payment never reaches the signer.

Design

  • Accepts '$5', '5' or 5, normalized to "$N". Validated at initX402() time: positive amounts only. 0, negatives, NaN, Infinity, exponent/comma forms, null and false throw. Disabling the cap (false) is intentionally not exposed; raising it must be an explicit, bounded choice.
  • Without the option setSpendControls is not called, so the $1 default and current behavior are unchanged.
  • Applied on both paths: plain x402Fetch and the policy path. With a policy, a payment above the cap is refused before the policy or the signer is consulted.
  • X402SpendCapError message now points to the option instead of saying it cannot be changed.

Tests (test/x402-spend-cap-config.test.ts, e2e on dist/ with the in-memory x402-edges fixtures)

  • default: a $1.01 payment fails with X402SpendCapError, cap $1, signer never called, no paid retry
  • raised ('$2', '2', 2, '1.01'): $1.01 pays, signed exactly once
  • raised to $5: just above $5 is still blocked before the signer
  • with policy + raised cap: pays under the cap; above it the policy is not asked and the signer is not called
  • invalid values throw at init
    Full suite on Node 22.12.0: jest 56/56, node:test 126/126.

Docs

README "Per-payment cap" documents the option and why the $1 default exists. CHANGELOG "Unreleased" entry.

AI disclosure

This PR was written with AI assistance under my direction: the AI read @x402/core 2.28.0, drafted the change, tests and docs. I reviewed the diff and the test results by hand before opening it.

@Eras256
Eras256 merged commit fb30603 into nirium-protocol:main Oct 13, 2026
1 check passed
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.

initX402(): no way to raise @x402/core's $1 per-payment cap

2 participants