A lightweight health monitoring tool for public x402-enabled APIs.
Built for the x402 ecosystem as an observability tool for public x402 APIs. Now fully compliant with x402 Protocol Specification v2.
x402-watch periodically verifies that x402-compliant endpoints behave correctly by asserting that:
- They return
402 Payment Requiredwhen accessed without payment. - They include a valid
PAYMENT-REQUIREDheader withx402Version: 2. - The header contains a well-formed, base64-encoded
PaymentRequiredobject withacceptsarray andpayTofield.
Ensure you have Rust installed.
cargo build --releaseRun a single check against a list of URLs:
./target/release/x402-watch --urls https://api.example.com/dataRun with a configuration file:
./target/release/x402-watch --config endpoints.yamlMonitor endpoints every 5 minutes:
./target/release/x402-watch --interval 5mTo verify the full payment lifecycle (402 -> Signing -> 200 OK), you must provide a private key with testnet USDC on Base Sepolia.
- Set your private key:
export X402_WATCH_PRIVATE_KEY=your_private_key_here
# On Windows PowerShell:
# $env:X402_WATCH_PRIVATE_KEY="your_private_key_here"- Run the tool:
cargo run -- --urls https://api.x402.org/demo --verify-settlement --settlement-timeout 60sThe tool will automatically detect the key, check your balance, and attempt the full payment cycle.
Create a configuration file with the APIs you want to monitor:
endpoints:
- name: "X402 Demo"
url: "https://api.x402.org/demo"
- name: "My Protected API"
url: "https://api.myapp.com/v1/protected"Monitor your endpoints in periodic mode with JSON output for your observability pipeline:
$env:X402_WATCH_PRIVATE_KEY="0x..."
cargo run -- --config endpoints.yaml --interval 10m --format json--- x402 Health Report ---
Endpoint | Status | Error Code | Message
----------------------------------------------------------------------------------------------------
X402 Demo | PASS | - | Full payment lifecycle verified
My Protected API | FAIL | SETTLEMENT_FAILURE | Settlement failure: expected 200 OK after signing, got 403 Forbidden
----------------------------------------------------------------------------------------------------
Output results in JSON format for CI/CD pipelines:
./target/release/x402-watch --format jsonJSON results will include error_code fields for automated diagnostics (e.g., INSUFFICIENT_FUNDS, SETTLEMENT_FAILURE).
- x402 v2 Compliant: Uses
x402Version,payTo, and structuredPaymentPayload - GET & POST Support: Configure HTTP method per endpoint via
--methodflag orendpoints.yaml - Dry-run validation: Verify 402 response and PaymentRequirement structure
- Full payment lifecycle: Sign and submit payments with automatic retries
- Balance verification: Check ETH and USDC balances before signing
- Smart retry logic: Exponential backoff for 202 Accepted / 425 Too Early
- Settlement verification: HTTP facilitator + on-chain fallback
- Multiple output formats: Human-readable and JSON for CI/CD
- Periodic monitoring: Configurable interval for continuous checks
Configure POST requests per endpoint in endpoints.yaml:
endpoints:
- name: "POST Protected API"
url: "https://api.example.com/v1/create"
method: "POST"
- name: "GET Demo"
url: "https://api.x402.org/demo"
method: "GET"Or use the --method flag for CLI-specified URLs:
cargo run -- --urls https://api.example.com/data --method POSTTo verify full x402 v2 compliance, test against the reference examples from the coinbase/x402 repository:
- Clone and run a reference server locally:
git clone https://github.com/coinbase/x402.git
cd x402/examples/typescript/servers/express
npm install
npm start- Test with x402-watch:
Verifies that the server returns a valid 402 Payment Required response with the correct v2 headers.
cargo run -- --urls http://localhost:4021/weatherExpected Message: Payment requirements validated (dry-run, x402 v2 compliant)
Verifies the full lifecycle: Request -> 402 -> Signing -> Re-submission -> 200 OK.
Unix/macOS:
X402_WATCH_PRIVATE_KEY=your_key_here cargo run -- --urls http://localhost:4021/weatherWindows PowerShell:
$env:X402_WATCH_PRIVATE_KEY="your_key_here"; cargo run -- --urls http://localhost:4021/weatherExpected Message: Full payment lifecycle verified (x402 v2 compliant)
This tool validates the following x402 v2 fields:
x402Version: Must be2(number, not string)accepts: Array of payment requirementspayTo: Recipient wallet address in each requirementscheme,network,asset,amount,maxTimeoutSeconds: Required fields
# Test POST endpoint
cargo run -- --urls https://api.example.com/create --method POST
# Or via endpoints.yaml with method field
cargo run -- --config endpoints.yamlThis project is licensed under the MIT License - see the LICENSE file for details.
