create-typescript-x402-client

Create TypeScript HTTP clients that automatically handle 402 payments on Algorand.

Updated Apr 6, 2026
One-click install
npx skills add https://github.com/Rudhrakoushik10/RootNode --skill create-typescript-x402-client-rudhrakoushik10
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-typescript-x402-client
Source: https://github.com/Rudhrakoushik10/RootNode/tree/main/projects/.opencode/skill/create-typescript-x402-client
Command: npx skills add https://github.com/Rudhrakoushik10/RootNode --skill create-typescript-x402-client-rudhrakoushik10

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @x402-avm/fetch, @x402-avm/axios, @x402-avm/avm, algosdk, axios, and includes references (resource) components.

What problem does it solve? Consuming x402-protected APIs requires manually detecting 402 Payment Required responses, signing Algorand payment transactions, and retrying requests with payment proof. This Skill guides you through building Fetch or Axios clients that automate that entire flow. ## Core Features & Use Cases - Automatic 402 Handling: Wrap fetch or Axios so 402 responses trigger transaction signing and a transparent retry with the PAYMENT-SIGNATURE header. - Flexible Signing: Implement ClientAvmSigner for Node.js private keys or browser wallets like Pera via @txnlab/use-wallet. - Payment Policies & Hooks: Filter payment requirements by amount or network and monitor the payment lifecycle with before/after/failure hooks. - Use Case: Build a Node.js CLI that fetches a premium API endpoint, automatically pays up to 5 USDC on Algorand testnet, and logs the settlement receipt from the PAYMENT-RESPONSE header. ## Quick Start Create an x402 fetch client that wraps fetch with payment handling using my Algorand private key from the AVM_PRIVATE_KEY environment variable.

Frequently Asked Questions about create-typescript-x402-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wrap fetch with automatic 402 payment handling?

Create an x402Client, call registerExactAvmScheme with your ClientAvmSigner, then pass fetch and the client to wrapFetchWithPayment from @x402-avm/fetch. The wrapped function intercepts 402 responses, signs the payment transaction, and retries with the PAYMENT-SIGNATURE header.

How do I add x402 payments to an Axios instance?

Use wrapAxiosWithPayment from @x402-avm/axios after registering the ExactAvmScheme on an x402Client. Add your own interceptors first and call wrapAxiosWithPayment last, since the payment interceptor should run after other response interceptors.

Can I use x402 payments with a browser wallet like Pera?

Yes, implement the ClientAvmSigner interface using @txnlab/use-wallet or PeraWalletConnect. The signer's signTransactions method delegates to the wallet's signing function, returning signed blobs for the requested transaction indexes.

What format does AVM_PRIVATE_KEY need for x402 signing?

AVM_PRIVATE_KEY must be a Base64-encoded 64-byte key consisting of a 32-byte seed plus a 32-byte public key. Derive the address with algosdk.encodeAddress(secretKey.slice(32)), never from the first 32 bytes.

Why does my x402 client fail with 'No network/scheme registered'?

This error means the server requested a payment network for which no scheme was registered. Call registerExactAvmScheme(client, { signer }) before wrapping fetch or Axios, or use the algorand:* wildcard in config-based setups to match any Algorand network.

How do I limit the maximum payment amount in x402 clients?

Register a PaymentPolicy on the x402Client that filters requirements by amount, for example keeping only requirements where BigInt(r.amount) is below your limit. Policies run in registration order, and you can also abort payments in an onBeforePaymentCreation hook.