phdargen dd6d7e6fc2
Harden workflows (#2287)
* add --ignore-scripts

* update to pnpm 11 and node 22

* align dep

* fix axios headers

* pin workflow actions

* fix paywall

* remove cache from publishing

* add hedera publishing

* remove e2e workflow

* increase minminimumReleaseAge to 3days
2026-05-13 17:33:05 +02:00
..
2026-02-19 15:29:43 -05:00
2025-07-06 02:36:14 -07:00
2025-07-06 02:36:14 -07:00
2025-12-11 07:41:57 -08:00
2025-07-06 02:36:14 -07:00
2026-05-04 16:43:57 -04:00
2025-12-11 07:41:57 -08:00
2026-05-13 17:33:05 +02:00
2025-07-06 02:36:14 -07:00
2025-12-11 07:41:57 -08:00

E2E Test Client: TypeScript Fetch

This client demonstrates and tests the @x402/fetch package with EVM, SVM, and Stellar payment support.

What It Tests

Core Functionality

  • ✅ V2 Protocol - Modern x402 protocol with CAIP-2 networks
  • ✅ V1 Protocol - Legacy x402 protocol with simple network names
  • ✅ Multi-chain Support - EVM, SVM, and (optional) Stellar in a single client
  • ✅ Automatic Payment Handling - Transparent 402 response handling
  • ✅ Payment Response Decoding - Extracts settlement information from headers

Payment Mechanisms

  • ✅ EVM V2 - eip155:* wildcard scheme
  • ✅ EVM V1 - base-sepolia and base networks
  • ✅ SVM V2 - solana:* wildcard scheme
  • ✅ SVM V1 - solana-devnet and solana networks
  • ✅ Stellar V2 - stellar:* wildcard scheme (optional)

What It Demonstrates

Usage Pattern

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmClient } from "@x402/evm";
import { ExactEvmClientV1 } from "@x402/evm/v1";
import { ExactSvmClient } from "@x402/svm";
import { ExactSvmClientV1 } from "@x402/svm/v1";
import { ExactStellarClient } from "@x402/stellar";

// Build x402 client with direct registration
const client = new x402Client()
  .register("eip155:*", new ExactEvmClient(evmAccount))
  .register("solana:*", new ExactSvmClient(svmSigner))
  .register("stellar:*", new ExactStellarClient(stellarSigner))
  .registerV1("base-sepolia", new ExactEvmClientV1(evmAccount))
  .registerV1("base", new ExactEvmClientV1(evmAccount))
  .registerV1("solana-devnet", new ExactSvmClientV1(svmSigner))
  .registerV1("solana", new ExactSvmClientV1(svmSigner));

// Wrap fetch with payment handling
const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// Make request - 402 responses handled automatically
const response = await fetchWithPayment(url, { method: "GET" });

Key Concepts Shown

  1. Builder Pattern - Fluent API for registering multiple schemes
  2. Multi-Version Support - V1 and V2 protocols side-by-side
  3. Multi-Chain Support - EVM, SVM, and (optional) Stellar in one client
  4. Network Flexibility - Wildcards for V2, specific networks for V1
  5. Transparent Payment - No manual 402 handling needed

Test Scenarios

This client is tested against:

  • Servers: Express (TypeScript), Gin (Go)
  • Facilitators: TypeScript, Go
  • Endpoints: /protected (EVM), /protected-svm (SVM), /protected-stellar (Stellar)
  • Networks: Base Sepolia (EVM), Solana Devnet (SVM), Stellar Testnet (Stellar)

Success Criteria

  • ✅ Request succeeds with 200 status
  • ✅ Payment response header present
  • ✅ Transaction hash returned
  • ✅ Payment marked as successful

Running

# Via e2e test suite
cd e2e
pnpm test --client=fetch

# Direct execution (requires environment variables)
cd e2e/clients/fetch
export RESOURCE_SERVER_URL="http://localhost:4022"
export ENDPOINT_PATH="/protected"
export EVM_PRIVATE_KEY="0x..."
export SVM_PRIVATE_KEY="..."
export STELLAR_PRIVATE_KEY="S..." # optional
pnpm start

Environment Variables

Required

  • RESOURCE_SERVER_URL - Server base URL
  • ENDPOINT_PATH - Path to protected endpoint
  • EVM_PRIVATE_KEY - Ethereum private key (hex with 0x prefix)
  • SVM_PRIVATE_KEY - Solana private key (base58 encoded)

Optional

  • STELLAR_PRIVATE_KEY - Stellar private key (S... format) - enables Stellar support

Output Format

{
  "success": true,
  "data": { "message": "Protected endpoint accessed" },
  "status_code": 200,
  "payment_response": {
    "success": true,
    "transaction": "0x...",
    "network": "eip155:84532",
    "payer": "0x..."
  }
}

Package Dependencies

  • @x402/fetch - HTTP wrapper with payment handling
  • @x402/core - Core x402 client and types
  • @x402/evm - EVM payment mechanisms (V2)
  • @x402/evm/v1 - EVM payment mechanisms (V1)
  • @x402/svm - SVM payment mechanisms (V2)
  • @x402/svm/v1 - SVM payment mechanisms (V1)
  • @x402/stellar - Stellar payment mechanisms (V2)
  • viem - Ethereum library for account creation
  • @solana/kit - Solana keypair utilities