Skip to content

Add x402 auto-payment via WalletConnect#3

Closed
arein wants to merge 1 commit intomainfrom
add-x402-auto-payment
Closed

Add x402 auto-payment via WalletConnect#3
arein wants to merge 1 commit intomainfrom
add-x402-auto-payment

Conversation

@arein
Copy link
Owner

@arein arein commented Feb 23, 2026

Summary

  • Automatically handle HTTP 402 (x402 payment required) responses when a WalletConnect wallet session is active
  • Constructs EIP-712 TransferWithAuthorization typed data, signs via walletconnect sign-typed-data, and retries the request with the Payment-Signature header
  • Adds --no-auto-pay flag to disable automatic payment; existing --x402-payment-signature manual override still works

Changes

  • src/x402.js (new) — x402 payment construction, EIP-712 typed data, walletconnect CLI integration
  • src/api.js — Intercept 402 responses in request(), auto-sign and retry when wallet connected
  • src/cli.js — Add --no-auto-pay global option
  • Tests — 15 new tests covering x402 functions, auto-pay flow, and flag parsing

Test plan

  • All 425 tests pass (npm test)
  • Tested end-to-end against live Nansen API with real wallet signing
  • Verify --no-auto-pay disables auto-payment
  • Verify --x402-payment-signature manual override skips auto-pay

🤖 Generated with Claude Code

When the API returns HTTP 402 and a WalletConnect wallet session is active,
automatically construct the x402 payment payload (EIP-712 TransferWithAuthorization),
send it to the wallet for signing, and retry the request with the Payment-Signature header.

- New src/x402.js module with EIP-712 typed data construction and walletconnect CLI integration
- Intercept 402 responses in api.js request() with automatic retry
- Add --no-auto-pay flag to disable automatic payment
- 15 new tests covering x402 functions and auto-pay flow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arein arein closed this Feb 23, 2026
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