Skip to content

Implement x402curl to print JavaScript code for x402-client#15

Merged
juntao merged 2 commits intomainfrom
implement-x402curl
Feb 1, 2026
Merged

Implement x402curl to print JavaScript code for x402-client#15
juntao merged 2 commits intomainfrom
implement-x402curl

Conversation

@juntao
Copy link
Member

@juntao juntao commented Feb 1, 2026

Summary

Implement the x402curl tool to print JavaScript code that uses the x402-client library.

The generated code:

  • Uses x402-client library to handle HTTP 402 payments
  • Loads wallet from ~/.payment/wallet.json and password from ~/.payment/password.txt
  • Accepts payment_url as a command line argument
  • Supports --max-payment option for payment limits

Usage

x402curl https://link.x402labs.dev/pay/abc123
x402curl https://link.x402labs.dev/pay/abc123 --max-payment 5

Test plan

  • cargo build --release succeeds
  • cargo test --all passes
  • Manual testing with example URLs

🤖 Generated with Claude Code

Juntao Yuan and others added 2 commits February 1, 2026 21:06
The tool prints JavaScript code that:
- Uses x402-client library to handle HTTP 402 payments
- Loads wallet from ~/.payment/wallet.json and password from ~/.payment/password.txt
- Accepts payment_url as command line argument
- Supports --max-payment option for payment limits

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Wrap the JavaScript code with clear instructions explaining:
- How to save and run the code
- The npm package dependency requirement

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the x402curl CLI tool, which prints a ready-to-run JavaScript example that uses the x402-client library to complete HTTP 402 payment flows.

Changes:

  • Add a clap-based argument parser for payment_url and an optional --max-payment flag.
  • Implement generate_code to produce a Node.js ESM script that reads the wallet and password from ~/.payment, initializes x402-client, and performs a fetchWithPayment to the provided URL.
  • Wire up the new x402curl binary in its own crate with the necessary clap dependency in Cargo.toml.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
x402curl/src/main.rs Defines CLI arguments and generates the JavaScript snippet that uses x402-client with optional maxPayment.
x402curl/Cargo.toml Registers the x402curl binary crate and adds clap as a dependency, consistent with other workspace tools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@juntao juntao merged commit d4ee64d into main Feb 1, 2026
17 checks passed
@juntao juntao deleted the implement-x402curl branch February 1, 2026 22:34
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.

2 participants