Skip to content

Add Mastra pre-pay x402 check example - #6

Open
killdabeat91 wants to merge 1 commit into
agent402-dev:mainfrom
killdabeat91:feat/mastra-prepay-check
Open

killdabeat91 wants to merge 1 commit into
agent402-dev:mainfrom
killdabeat91:feat/mastra-prepay-check

Conversation

@killdabeat91

Copy link
Copy Markdown

/claim #3

Adds a small runnable Mastra example at examples/mastra-prepay-check/ (README.md, package.json, src/index.ts) that checks an x402 endpoint before paying it.

Summary

  • Defines a Mastra createTool (check402) that calls runCheck402({ url }) from @agent402-dev/ai-sdk-tools and returns its result (one HTTP request without a payment header; nothing signed or paid; no wallet, key, or RPC read).
  • Configures the Mastra Agent instructions to report the price and fixes count, and not pay when fixes > 0 (or when fixes is null).
  • Pins exact dependency versions in examples/mastra-prepay-check/package.json.
  • Documents install, run (live + local broken 402), result fields, non-payment note, and tested versions in README.md.
  • Does not modify any payment code, payment rules/limits, keys, wallets, or signing.

Versions tested

  • @mastra/core: 1.87.0
  • @agent402-dev/ai-sdk-tools: 0.1.0
  • zod: 4.3.6
  • tsx: 4.23.15
  • Model: google/gemini-2.5-flash
  • Node.js: v24.12.0

Local verification

  1. npm install && npm run typecheck — passed with exit code 0.
  2. Live x402 endpoint (https://agent402-tx-receipts.agent402-ebc.workers.dev/x402/receipts?signatures=5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW):
- **Price**: 0.05 USDC (50,000 base units on Solana mainnet or Base)
- **Fixes count**: 0
- **Key findings**:
  - Payment-required header decodes successfully.
  - Discovery metadata is present.
  - Note regarding Solana transaction version 1 support (`maxSupportedTransactionVersion: 1`).
- **Would I pay?**: Yes, because the fixes count is 0 and all checks are clear.
  1. Local broken 402 server (http://127.0.0.1:4021/paid returning HTTP 402 without PAYMENT-REQUIRED):
I checked the x402 paid endpoint at `http://127.0.0.1:4021/paid`:

* **Price:** No USDC amounts were reported in the x402 response.
* **Fixes count:** `1` (there is 1 fix finding: `header_missing` - HTTP 402 without a PAYMENT-REQUIRED header).
* **Payment decision:** **I would not pay.** Since the fixes count is greater than 0 (`fixes: 1`) and the endpoint failed to return a proper `PAYMENT-REQUIRED` header, the endpoint is improperly configured or not a valid x402 payment endpoint.

@opirebot

opirebot Bot commented Dec 5, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.

This branch has not been deployed

No deployments
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