Skip to content

x402 faremeter solana example#1207

Open
fainashalts wants to merge 21 commits intomainfrom
x402-faremeter-solana-example
Open

x402 faremeter solana example#1207
fainashalts wants to merge 21 commits intomainfrom
x402-faremeter-solana-example

Conversation

@fainashalts
Copy link

@fainashalts fainashalts commented Feb 19, 2026

This PR adds a new example/with-x402-faremeter flow for headless Solana x402 payments using Turnkey + Faremeter.

What Changed

  • Added a complete with-x402-faremeter example with:
    • Turnkey API-key auth (headless)
    • Solana wallet create/reuse logic
    • SOL + USDC balance checks
    • Paywalled fetch flow via @faremeter/fetch + @faremeter/payment-solana/exact
  • Uses Faremeter v0.17.0 for native x402 v2 protocol support, lenient v1
    response parsing, and CAIP-2 network identifier handling
  • Includes a minimal patchV2Fetch workaround for servers (e.g. Echo)
    that send a PAYMENT-REQUIRED header without the required resource object
Screenshot 2026-02-19 at 9 05 41 AM

Test Plan

    • pnpm --filter @turnkey/example-with-x402-faremeter typecheck
    • pnpm start in examples/with-x402-faremeter with:
      • TEST_PAYWALL_URL=https://x402.payai.network/api/solana-devnet/paid-content
    • Verified successful paid fetch flow (✅ Content received!) and final balance reporting.

Note
Echo server uses gasless settlement semantics (server covers SOL fee);
Faremeter's exact payment handler supports this path directly via extra.feePayer.

@socket-security
Copy link

socket-security bot commented Feb 19, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​faremeter/​fetch@​0.17.176100829470
Added@​faremeter/​payment-solana@​0.17.177100809370
Added@​faremeter/​types@​0.17.180100829470
Addedtsx@​4.21.01001008185100

View full report

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 19, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c8fc5f4:

Sandbox Source
@turnkey/example-react-components Configuration

@cylon56
Copy link
Contributor

cylon56 commented Feb 25, 2026

any reason we haven't merged this yet? Definitely something I'd like to reference for some customers

…yments

Add a new example demonstrating how AI agents can use Turnkey wallets
to autonomously pay for x402-protected resources on Solana using
Faremeter.

- Headless auth via API keys (no browser/WebAuthn)
- Wallet creation/retrieval using @turnkey/sdk-server + @turnkey/solana
- Faremeter wrapFetch integration for automatic 402 payment handling
- Follows existing repo conventions (env var naming, package.json shape)
…upport

- Implement custom gasless payment handler for Echo server compatibility
- Add v2 protocol support (accepted field, CAIP-2 network IDs)
- Use correct Solana transaction structure (3 instructions)
- Add USDC balance checking
- Update README with accurate usage instructions
Track v2 payment context per transaction instead of global vars to prevent cross-request/race mismatches in adapted payment headers.
Extract protocol internals (gasless handler, v2 normalization) into
x402-client.ts, exposing a single createX402Client() factory. This
makes the agent integration pattern clearer in index.ts.
Include copy-paste snippets for OpenAI function calling, Anthropic
tool use, and a generic agent pattern
  Bump @faremeter/* deps to ^0.17.0 and remove ~230 lines of
  protocol workaround code (normalizing fetch, adaptive v2 headers,
  CAIP-2 mapping) now handled natively by faremeter. Add
  partiallySignTransaction to wallet adapter per updated interface.
…phase1Fetch to patch PAYMENT-REQUIRED headers missing the resource object, which the Echo server doesn't include yet.
@fainashalts fainashalts force-pushed the x402-faremeter-solana-example branch from 81736ee to 9ab8e96 Compare March 17, 2026 22:12
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