### Setup: Start the example client Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/fetch/README.md Run the example client with pnpm dev. ```bash pnpm dev ``` -------------------------------- ### Setup: Install and build packages Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/discovery/README.md Run from the typescript examples root to install dependencies and build all packages before starting the discovery example. ```bash cd ../../ pnpm install pnpm build cd examples/typescript/discovery ``` -------------------------------- ### Install and build all packages from the typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/next/README.md Setup step to install dependencies and build packages from the typescript examples root. ```bash cd ../../ pnpm install pnpm build cd fullstack/next ``` -------------------------------- ### Setup: Install and build packages Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/fetch/README.md Run these commands from the typescript examples root to install dependencies and build all packages, then navigate to the fetch client directory. ```bash cd ../../ pnpm install pnpm build cd clients/fetch ``` -------------------------------- ### Install and build all packages from the typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/mainnet/README.md Setup step: run from the typescript examples root to install dependencies and build all packages. ```bash cd ../../ pnpm install pnpm build cd servers/mainnet ``` -------------------------------- ### Setup: Install and build packages Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/next-advanced/README.md Navigate to the TypeScript directory, install dependencies, build all packages, then return to the example directory. ```bash cd ../../../../typescript pnpm install pnpm build cd ../examples/typescript/fullstack/next-advanced ``` -------------------------------- ### Install and build all packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/advanced/README.md Setup step: navigate to the typescript examples root, install dependencies, build, and return to the advanced server directory. ```bash cd ../../ pnpm install pnpm build cd servers/advanced ``` -------------------------------- ### Setup: Install and build packages Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/axios/README.md Run from the typescript examples root to install dependencies and build all packages, then navigate to the axios client directory. ```bash cd ../../ pnpm install pnpm build cd clients/axios ``` -------------------------------- ### Start Facilitator - Setup Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Navigate to the facilitator directory and copy the .env-local file to .env. ```bash cd examples/typescript/facilitator cp .env-local .env ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/facilitator/README.md Run these commands from the typescript examples root to install dependencies and build all packages before starting the facilitator. ```bash cd .. pnpm install pnpm build cd facilitator ``` -------------------------------- ### Run the Hono server Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/hono/README.md Install dependencies and start the development server. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install dependencies for examples Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/README.md Shows two options for installing dependencies: sync each example individually with `uv sync` in its directory, or run the helper script `sync.py` from the `examples/python` directory to sync all examples. ```bash # Option A: sync each example individually (recommended by each example README) cd uv sync # Option B: run the helper script to sync all examples cd examples/python uv run python sync.py ``` -------------------------------- ### Start VRF Resource Server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Install dependencies and start the VRF resource server. ```bash cd examples/typescript/clients/chainlink-vrf-nft npx pnpm install pnpm run resource ``` -------------------------------- ### Copy .env Example Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Create a .env file in this directory by copying the example file. ```bash cp .env.example .env ``` -------------------------------- ### Install and build all packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/express/README.md Navigate to the typescript examples root, install dependencies, build all packages, then return to the express server directory. ```bash cd ../../ pnpm install pnpm build cd servers/express ``` -------------------------------- ### Install and Build Example Dependencies Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Install and build the example's TypeScript dependencies. ```bash cd ../examples/typescript npx pnpm install npx pnpm build ``` -------------------------------- ### Install dependencies with uv sync Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/requests/README.md Install project dependencies using uv. ```bash uv sync ``` -------------------------------- ### Install and Build All Packages from TypeScript Examples Root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/farcaster-miniapp/README.md Navigate to the typescript examples root, install dependencies, build all packages, then return to the farcaster-miniapp directory. ```bash cd ../../ ``` ```bash pnpm install ``` ```bash pnpm build ``` ```bash cd fullstack/farcaster-miniapp ``` -------------------------------- ### Install and build packages from python examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/discovery/README.md Run these commands from the python examples root to install dependencies and navigate to the discovery example directory. ```bash cd ../../ uv sync cd examples/python/discovery ``` -------------------------------- ### Install and build all packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/hono/README.md Navigate to the typescript examples root, install dependencies, build all packages, then change to the Hono server directory. ```bash cd ../../ pnpm install pnpm build cd servers/hono ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/mcp/README.md Run from the typescript examples root to install dependencies and build all packages, then navigate to the MCP client directory. ```bash cd ../../ pnpm install pnpm build cd clients/mcp ``` -------------------------------- ### GET /api/pricing Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Get pricing information for the available premium tiers. Returns the pricing details for each paid endpoint. ```APIDOC ## [GET] /api/pricing ### Description Get pricing information for the available premium tiers. Returns the pricing details for each paid endpoint. ### Method GET ### Endpoint /api/pricing ``` -------------------------------- ### Install and Build Parent Dependencies Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Install and build the parent TypeScript dependencies before running the example. ```bash cd typescript npx pnpm install npx pnpm build ``` -------------------------------- ### Install dependencies and build packages Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/README.md Run from the examples/typescript directory before running any examples. Installs dependencies with pnpm and builds the packages. ```bash # From the examples/typescript directory pnpm install pnpm build ``` -------------------------------- ### Expected Server Startup Output Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Expected output when the AnySpend server starts successfully. ```text 🚀 AnySpend Express Server with Remote Facilitator =================================================== Server running on: http://localhost:3001 ``` -------------------------------- ### Run the examples Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/httpx/README.md Commands to run the simple and extensible examples. ```bash # Simple approach uv run python main.py # Extensible approach uv run python extensible.py ``` -------------------------------- ### Run the Demo Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Start the demo with pnpm start. The client creates a signed payment message, sends it via HTTP header, and the server verifies and settles the transaction. ```bash pnpm start ``` -------------------------------- ### Test with Fetch Client Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/advanced/README.md Testing step: navigate to the fetch client directory, ensure .env is set up, install dependencies, and run the client. ```bash cd ../../clients/fetch # Ensure .env is setup pnpm install pnpm dev ``` -------------------------------- ### Use a Different Network Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Run the demo on the Base network by setting the NETWORK environment variable. ```bash NETWORK=base pnpm start ``` -------------------------------- ### Copy .env.local to .env Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/next/README.md Setup step to copy the environment file and add your Ethereum address for receiving payments. ```bash cp .env.local .env ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/agent/README.md Run these commands from the typescript examples root to install dependencies and build all packages, then navigate to the agent client directory. ```bash cd ../../ pnpm install pnpm build cd clients/agent ``` -------------------------------- ### Run an example Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/README.md General instructions for running any example: copy the `.env-local` file to `.env`, fill in required values, sync dependencies with `uv sync`, and run `main.py`. Some client examples also provide an `extensible.py` variant for lower-level integrations. ```bash cd cp .env-local .env # then fill in required values uv sync uv run python main.py ``` -------------------------------- ### Pay with WETH Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Run the demo paying with WETH by setting the PAYMENT_TOKEN environment variable. ```bash # Pay with WETH PAYMENT_TOKEN=0x4200000000000000000000000000000000000006 pnpm start ``` -------------------------------- ### Run examples: main.py and extensible.py Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/requests/README.md Run either the simple or extensible example script. ```bash # Simple approach python main.py # Extensible approach python extensible.py ``` -------------------------------- ### Test with Fetch client Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/hono/README.md Navigate to the fetch client directory, ensure .env is set up, install dependencies, and run the client to test the server. ```bash cd ../clients/fetch # Ensure .env is setup pnpm install pnpm dev ``` -------------------------------- ### Install This Project's Dependencies Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Install the dependencies for the chainlink-vrf-nft client project. ```bash cd clients/chainlink-vrf-nft pnpm install ``` -------------------------------- ### Pay with DAI Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Run the demo paying with DAI by setting the PAYMENT_TOKEN environment variable. ```bash # Pay with DAI PAYMENT_TOKEN=0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb pnpm start ``` -------------------------------- ### Run the FastAPI server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/fullstack/fastapi/README.md Starts the server on http://localhost:4021. ```bash uv run python main.py ``` -------------------------------- ### Install required dependencies Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/mcp/README.md Install the required npm packages for using the x402 MCP pattern in your own application. ```bash npm install @modelcontextprotocol/sdk x402-axios viem ``` -------------------------------- ### Install Go x402 package Source: https://github.com/b3-fun/anyspend-x402/blob/main/go/README.md Use `go get` to install the Go x402 library from GitHub. ```bash go get github.com/coinbase/x402/go ``` -------------------------------- ### Configure Private Key in .env Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Edit the .env file and add your private key. Ensure your wallet has USDC and ETH on Base Sepolia. ```env PRIVATE_KEY=0x1234567890abcdef... ``` -------------------------------- ### Start the AnySpend Server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Run these commands in a separate terminal to start the AnySpend Express server with the remote facilitator. The server runs on http://localhost:3001. ```bash cd examples/typescript/fullstack/anyspend pnpm install pnpm dev:server ``` -------------------------------- ### Test with Axios Client Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/advanced/README.md Testing step: navigate to the axios client directory, ensure .env is set up, install dependencies, and run the client. ```bash cd ../../clients/axios # Ensure .env is setup pnpm install pnpm dev ``` -------------------------------- ### Example: Wrap fetch with x402 payment handling Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/fetch/README.md This TypeScript example creates a viem wallet client, wraps the native fetch with x402 payment handling, and makes a GET request to a paid endpoint. It uses environment variables for configuration and logs the response body or error. ```typescript import { config } from "dotenv"; import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { wrapFetchWithPayment } from "x402-fetch"; import { baseSepolia } from "viem/chains"; config(); const { RESOURCE_SERVER_URL, PRIVATE_KEY, ENDPOINT_PATH } = process.env; // Create wallet client const account = privateKeyToAccount(PRIVATE_KEY as `0x${string}`); const client = createWalletClient({ account, transport: http(), chain: baseSepolia, }); // Wrap fetch with payment handling const fetchWithPay = wrapFetchWithPayment(fetch, client); // Make request to paid endpoint fetchWithPay(`${RESOURCE_SERVER_URL}${ENDPOINT_PATH}`, { method: "GET", }) .then(async response => { const body = await response.json(); console.log(body); }) .catch(error => { console.error(error.response?.data?.error); }); ``` -------------------------------- ### Test with Axios client Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/hono/README.md Navigate to the axios client directory, ensure .env is set up, install dependencies, and run the client to test the server. ```bash cd ../clients/axios # Ensure .env is setup pnpm install pnpm dev ``` -------------------------------- ### Install Foundry and generate a new wallet Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/README.md Commands to install Foundry and generate a new wallet using cast. Use the generated address to fund your wallet via the testnet CDP Faucet. ```bash # install foundry curl -L https://foundry.paradigm.xyz | bash # generate a new wallet cast w new ``` -------------------------------- ### POST /api/premium/action Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Perform a premium action. This endpoint requires a payment of $1.00 and executes the specified premium action. ```APIDOC ## [POST] /api/premium/action ### Description Perform a premium action. This endpoint requires a payment of $1.00 and executes the specified premium action. ### Method POST ### Endpoint /api/premium/action ``` -------------------------------- ### POST /api/premium/content Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Access premium content. This endpoint requires a payment of $0.10 and returns the premium content. ```APIDOC ## [POST] /api/premium/content ### Description Access premium content. This endpoint requires a payment of $0.10 and returns the premium content. ### Method POST ### Endpoint /api/premium/content ``` -------------------------------- ### Copy .env-local to .env Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/hono/README.md Initial setup step to copy the environment template and add your Ethereum address for receiving payments. ```bash cp .env-local .env ``` -------------------------------- ### Manual Testing Commands for AnySpend X402 Source: https://github.com/b3-fun/anyspend-x402/blob/main/ANYSPEND-INTEGRATION.md Commands to install dependencies and run examples with default USDC payment or with payment preferences. Requires setting PRIVATE_KEY, RESOURCE_SERVER_URL, and ENDPOINT_PATH environment variables. ```bash # Install dependencies pnpm install # Run example with default payment (USDC) cd examples/typescript/clients/fetch PRIVATE_KEY=0x... RESOURCE_SERVER_URL=... ENDPOINT_PATH=/data npm start # Run example with payment preferences npm run start:preferences ``` -------------------------------- ### Create Client Environment File Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/anyspend/ANYSPEND-INTEGRATION.md Copy the example environment file to create the client configuration file at apps/client/.env. ```bash cp apps/client/.env.example apps/client/.env ``` -------------------------------- ### Install x402 with pip Source: https://github.com/b3-fun/anyspend-x402/blob/main/python/x402/README.md Install the x402 Python package using pip. ```bash pip install x402 ``` -------------------------------- ### Start AnySpend server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/README.md Run these commands to start the AnySpend server, resolving 'Connection refused' errors. ```bash cd examples/typescript/fullstack/anyspend pnpm dev:server ``` -------------------------------- ### Simple approach with x402_requests Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/requests/README.md Uses x402_requests to get a pre-configured session that handles payments automatically. ```python from x402.clients import x402_requests session = x402_requests(account) response = session.get(url) ``` -------------------------------- ### Run payment preferences example Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/axios/README.md Run the example with payment preferences (multi-token support). Demonstrates paying with WETH, cross-chain payments, DAI, and reusable client configuration. ```bash pnpm dev:preferences ``` -------------------------------- ### Sample response from GET /supported Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/facilitator/README.md Returns the payment kinds supported by the facilitator, including network and fee payer details. ```json5 [ { "x402Version": 1, "scheme": "exact", "network": "base-sepolia" "extra": {} }, { "x402Version": 1, "scheme": "exact", "network": "solana-devnet" "extra": { "feePayer": "SolanaAddress" } }, ] ``` -------------------------------- ### Create Server Environment File Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/anyspend/ANYSPEND-INTEGRATION.md Copy the example environment file to create the server configuration file at apps/server/.env. ```bash cp apps/server/.env.example apps/server/.env ``` -------------------------------- ### Start index server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/dynamic_agent/README.md Runs the index server that mocks an index of tools the agent may access via HTTP. ```bash pnpm run index-server ``` -------------------------------- ### Install with yarn Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Install the package using yarn. ```bash yarn add @b3dotfun/anyspend-x402-token-compat ``` -------------------------------- ### POST /api/premium/subscribe Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Monthly subscription endpoint. This endpoint requires a payment of $5.00 and subscribes the user to a monthly plan. ```APIDOC ## [POST] /api/premium/subscribe ### Description Monthly subscription endpoint. This endpoint requires a payment of $5.00 and subscribes the user to a monthly plan. ### Method POST ### Endpoint /api/premium/subscribe ``` -------------------------------- ### GET /verify Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/facilitator/README.md Returns information about the verify endpoint. This is a simple informational endpoint. ```APIDOC ## GET /verify ### Description Returns information about the verify endpoint. ### Method GET ### Endpoint /verify ``` -------------------------------- ### Install dependencies with pnpm Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/README.md Run from the repository root to install all dependencies for the demo. ```bash pnpm install ``` -------------------------------- ### Install with pnpm Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Install the package using pnpm. ```bash pnpm add @b3dotfun/anyspend-x402-token-compat ``` -------------------------------- ### Install @coinbase/x402 Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-next/README.md Install the official Coinbase facilitator package. ```bash npm install @coinbase/x402 ``` -------------------------------- ### Install with npm Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Install the package using npm. ```bash npm install @b3dotfun/anyspend-x402-token-compat ``` -------------------------------- ### Install Dependencies with npm run install:all Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/README.md Installs all dependencies for the template. Run this first before configuring the server. ```bash npm run install:all ``` -------------------------------- ### Installation: npm packages for fetch, axios, and facilitator Source: https://github.com/b3-fun/anyspend-x402/blob/main/ANYSPEND-INTEGRATION.md Install the required npm packages: x402-fetch for fetch-based apps, x402-axios for axios-based apps, and @b3dotfun/anyspend-x402 for facilitator integration. ```bash # For fetch-based applications npm install x402-fetch # For axios-based applications npm install x402-axios # For facilitator integration (resource servers) npm install @b3dotfun/anyspend-x402 ``` -------------------------------- ### Quick Start: wrapFetchWithPayment with viem wallet client Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-fetch/README.md Creates a viem wallet client on baseSepolia, wraps the native fetch with payment handling, and makes a GET request that may require payment. ```typescript import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { wrapFetchWithPayment } from "@b3dotfun/anyspend-x402-fetch"; import { baseSepolia } from "viem/chains"; // Create a wallet client const account = privateKeyToAccount("0xYourPrivateKey"); const client = createWalletClient({ account, transport: http(), chain: baseSepolia, }); // Wrap the fetch function with payment handling const fetchWithPay = wrapFetchWithPayment(fetch, client); // Make a request that may require payment const response = await fetchWithPay("https://api.example.com/paid-endpoint", { method: "GET", }); const data = await response.json(); ``` -------------------------------- ### Install @b3dotfun/anyspend-x402-fetch Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-fetch/README.md Install the package via npm. ```bash npm install @b3dotfun/anyspend-x402-fetch ``` -------------------------------- ### Install @b3dotfun/anyspend-x402-next Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-next/README.md Install the package via npm. ```bash npm install @b3dotfun/anyspend-x402-next ``` -------------------------------- ### Start the proxy server Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/agent/README.md Run the proxy server with the configuration file. ```bash go run proxy_demo.go anthropic_config.json ``` -------------------------------- ### Run VRF Client Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Run the VRF client script. ```bash cd examples/typescript/clients/chainlink-vrf-nft pnpm run client ``` -------------------------------- ### GET /supported Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/facilitator/README.md Returns the payment kinds that the facilitator supports. This endpoint provides information about the supported payment schemes and networks. ```APIDOC ## GET /supported ### Description Returns the payment kinds that the facilitator supports. ### Method GET ### Endpoint /supported ### Response #### Success Response (200) - **x402Version** (number) - The x402 protocol version. - **scheme** (string) - The payment scheme (e.g., "exact"). - **network** (string) - The network (e.g., "base-sepolia", "solana-devnet"). - **extra** (object) - Additional details (e.g., feePayer for Solana). #### Response Example ```json5 [ { "x402Version": 1, "scheme": "exact", "network": "base-sepolia", "extra": {} }, { "x402Version": 1, "scheme": "exact", "network": "solana-devnet", "extra": { "feePayer": "SolanaAddress" } } ] ``` ``` -------------------------------- ### TypeScript example using cdp-sdk server wallets with x402-axios Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/cdp-sdk/README.md Creates a server wallet account via cdp-sdk, sets up an Axios instance with payment interceptor, and makes a GET request to a paid endpoint, logging the response or error. ```typescript import { config } from "dotenv"; import { createWalletClient, http, publicActions } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { withPaymentInterceptor } from "x402-axios"; import axios from "axios"; import { baseSepolia } from "viem/chains"; config(); const { RESOURCE_SERVER_URL, CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET, ENDPOINT_PATH } = process.env; // Create a server wallet account const client = new CdpClient({ apiKeyId, apiKeySecret, walletSecret, }); const serverAccount = await client.evm.getOrCreateAccount({ name: "x402-axios-example", }) // Create Axios instance with payment handling const api = withPaymentInterceptor( axios.create({ baseURL: RESOURCE_SERVER_URL, }), account ); // Make request to paid endpoint api .get(ENDPOINT_PATH) .then(response => { console.log(response.headers); console.log(response.data); }) .catch(error => { console.error(error.response?.data?.error); }); ``` -------------------------------- ### Example: Create wallet client and Axios instance with payment interceptor Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/axios/README.md Demonstrates using x402-axios to make a paid HTTP request. Creates a viem wallet client, wraps an Axios instance with withPaymentInterceptor, and makes a GET request to a paid endpoint, logging headers and data or the error response. ```typescript import { config } from "dotenv"; import { createWalletClient, http, publicActions } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { withPaymentInterceptor } from "x402-axios"; import axios from "axios"; import { baseSepolia } from "viem/chains"; config(); const { RESOURCE_SERVER_URL, PRIVATE_KEY, ENDPOINT_PATH } = process.env; // Create wallet client const account = privateKeyToAccount(PRIVATE_KEY as "0x${string}"); const client = createWalletClient({ account, transport: http(), chain: baseSepolia, }).extend(publicActions); // Create Axios instance with payment handling const api = withPaymentInterceptor( axios.create({ baseURL: RESOURCE_SERVER_URL, }), client ); // Make request to paid endpoint api .get(ENDPOINT_PATH) .then(response => { console.log(response.headers); console.log(response.data); }) .catch(error => { console.error(error.response?.data?.error); }); ``` -------------------------------- ### Expected Demo Output Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/fetch-anyspend-demo/QUICK_START.md Expected output when running the demo, showing health check and premium endpoint responses. ```text 🚀 AnySpend Fetch Demo ════════════════════════════════════════ 📡 Server URL: http://localhost:3001 🌐 Network: base-sepolia 🔐 Creating signer from private key... ✅ Signer created for base-sepolia Example 1: Free Endpoint (No Payment) ✅ Health check response: { status: "healthy" } Example 2: Premium Endpoint with Default Payment (USDC) 📤 Making request to /api/premium... ✅ Response status: 200 OK 💳 Payment settled! Transaction: 0xabc123... 📊 Premium Market Analysis Data received! ``` -------------------------------- ### GET /api/health Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Server health check endpoint. Returns the health status of the server. ```APIDOC ## [GET] /api/health ### Description Server health check endpoint. Returns the health status of the server. ### Method GET ### Endpoint /api/health ``` -------------------------------- ### Install @b3dotfun/anyspend-x402-solana-wallet-adapter Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-solana-wallet-adapter/README.md Install the package using npm, pnpm, or yarn. The package bridges Solana wallet-adapter v1 with x402 v2. ```bash npm install @b3dotfun/anyspend-x402-solana-wallet-adapter # or pnpm add @b3dotfun/anyspend-x402-solana-wallet-adapter # or yarn add @b3dotfun/anyspend-x402-solana-wallet-adapter ``` -------------------------------- ### Navigate to proxy directory Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/agent/README.md Change to the go/bin directory to configure and start the proxy server. ```bash cd go/bin ``` -------------------------------- ### GET /api/session/:sessionId Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/browser-wallet-example/server/README.md Check the status of a payment session. Use the session ID to retrieve the current state of a payment session. ```APIDOC ## [GET] /api/session/:sessionId ### Description Check the status of a payment session. Use the session ID to retrieve the current state of a payment session. ### Method GET ### Endpoint /api/session/:sessionId ### Parameters #### Path Parameters - **sessionId** (string) - Required - The unique identifier of the payment session. ``` -------------------------------- ### Install peer dependencies for wallet adapter Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-solana-wallet-adapter/README.md Install the required peer dependencies, typically already present in browser apps. ```bash npm install @solana/wallet-adapter-base @solana/wallet-adapter-react @solana/wallet-adapter-react-ui @solana/web3.js react ``` -------------------------------- ### Start backend server in development mode Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/auth_based_pricing/README.md Use this command in Terminal 1 to start the backend server with auto-reloading. The server will start at http://localhost:3000 by default. ```bash npm run dev:server ``` -------------------------------- ### Install @b3dotfun/anyspend-x402-express Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-express/README.md Install the package via npm. ```bash npm install @b3dotfun/anyspend-x402-express ``` -------------------------------- ### GET /dynamic-price Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/servers/advanced/README.md Shows how to implement variable pricing based on request parameters. Accepts a multiplier query parameter to adjust the base price and demonstrates how to calculate and validate payments with dynamic amounts. ```APIDOC ## GET /dynamic-price ### Description Shows how to implement variable pricing based on request parameters. Accepts a multiplier query parameter to adjust the base price and demonstrates how to calculate and validate payments with dynamic amounts. ### Method GET ### Endpoint /dynamic-price ### Parameters #### Query Parameters - **multiplier** (number) - Required - Adjusts the base price. ### Response #### Success Response (200) Returns the dynamic pricing result. #### Response Example { "report": { "weather": "sunny", "temperature": 70 } } ``` -------------------------------- ### Install dependencies with npm install Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/auth_based_pricing/README.md Run this command in the project root to install required dependencies. ```bash npm install ``` -------------------------------- ### GET /dynamic-price Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/advanced/README.md Shows how to implement variable pricing based on request parameters. Accepts a `multiplier` query parameter to adjust the base price, demonstrating how to calculate and validate payments with dynamic amounts. ```APIDOC ## [GET] /dynamic-price ### Description Shows how to implement variable pricing based on request parameters. Accepts a `multiplier` query parameter to adjust the base price, demonstrating how to calculate and validate payments with dynamic amounts. ### Method GET ### Endpoint /dynamic-price ### Parameters #### Query Parameters - **multiplier** (number) - Required - Adjusts the base price for dynamic pricing. ### Response #### Success Response (200) - **report** (object) - Weather report data #### Response Example { "report": { "weather": "sunny", "temperature": 70 } } #### Payment Required (402) - **x402Version** (number) - Version of the x402 protocol - **error** (string) - Error message indicating payment required - **accepts** (array) - List of payment options - **scheme** (string) - Payment scheme (e.g., "exact") - **network** (string) - Network identifier (e.g., "base-sepolia") - **maxAmountRequired** (string) - Maximum amount required for payment - **resource** (string) - Resource URL - **description** (string) - Description of the resource - **mimeType** (string) - MIME type of the resource - **payTo** (string) - Payment recipient address - **maxTimeoutSeconds** (number) - Maximum timeout in seconds - **asset** (string) - Asset contract address - **outputSchema** (null) - Output schema (null) - **extra** (object) - Additional metadata - **name** (string) - Asset name - **version** (string) - Asset version #### Response Example (402) { "x402Version": 1, "error": "X-PAYMENT header is required", "accepts": [ { "scheme": "exact", "network": "base-sepolia", "maxAmountRequired": "1000", "resource": "http://localhost:3001/weather", "description": "Access to weather data", "mimeType": "", "payTo": "0xYourAddress", "maxTimeoutSeconds": 60, "asset": "0x...", "outputSchema": null, "extra": { "name": "USD Coin", "version": "1" } } ] } ``` -------------------------------- ### Extending the example - adding more protected routes Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/servers/next/README.md Update the middleware configuration to protect additional routes like /api/premium with different prices. ```typescript export const middleware = paymentMiddleware( payTo, { "/protected": { price: "$0.01", network, config: { description: "Access to protected content", }, }, "/api/premium": { price: "$0.10", network, config: { description: "Premium API access", }, }, } ); export const config = { matcher: ["/protected/:path*", "/api/premium/:path*"], }; ``` -------------------------------- ### GET /multiple-payment-requirements Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/servers/advanced/README.md Illustrates how to accept multiple payment options. Allows clients to pay using different assets (e.g., USDC or custom tokens) and supports multiple networks (e.g., Base and Base Sepolia). ```APIDOC ## GET /multiple-payment-requirements ### Description Illustrates how to accept multiple payment options. Allows clients to pay using different assets (e.g., USDC or custom tokens) and supports multiple networks (e.g., Base and Base Sepolia). ### Method GET ### Endpoint /multiple-payment-requirements ### Response #### Success Response (200) Returns the result with multiple payment options. #### Response Example { "report": { "weather": "sunny", "temperature": 70 } } ``` -------------------------------- ### GET /multiple-payment-requirements Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/servers/advanced/README.md Illustrates how to accept multiple payment options. Allows clients to pay using different assets (e.g., USDC or USDT) and supports multiple networks (e.g., Base and Base Sepolia). ```APIDOC ## [GET] /multiple-payment-requirements ### Description Illustrates how to accept multiple payment options. Allows clients to pay using different assets (e.g., USDC or USDT) and supports multiple networks (e.g., Base and Base Sepolia). ### Method GET ### Endpoint /multiple-payment-requirements ### Response #### Success Response (200) - **report** (object) - Weather report data #### Response Example { "report": { "weather": "sunny", "temperature": 70 } } #### Payment Required (402) - **x402Version** (number) - Version of the x402 protocol - **error** (string) - Error message indicating payment required - **accepts** (array) - List of payment options - **scheme** (string) - Payment scheme (e.g., "exact") - **network** (string) - Network identifier (e.g., "base-sepolia") - **maxAmountRequired** (string) - Maximum amount required for payment - **resource** (string) - Resource URL - **description** (string) - Description of the resource - **mimeType** (string) - MIME type of the resource - **payTo** (string) - Payment recipient address - **maxTimeoutSeconds** (number) - Maximum timeout in seconds - **asset** (string) - Asset contract address - **outputSchema** (null) - Output schema (null) - **extra** (object) - Additional metadata - **name** (string) - Asset name - **version** (string) - Asset version #### Response Example (402) { "x402Version": 1, "error": "X-PAYMENT header is required", "accepts": [ { "scheme": "exact", "network": "base-sepolia", "maxAmountRequired": "1000", "resource": "http://localhost:3001/weather", "description": "Access to weather data", "mimeType": "", "payTo": "0xYourAddress", "maxTimeoutSeconds": 60, "asset": "0x...", "outputSchema": null, "extra": { "name": "USD Coin", "version": "1" } } ] } ``` -------------------------------- ### Install @b3dotfun/anyspend-x402-hono Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-hono/README.md Install the package via npm. ```bash npm install @b3dotfun/anyspend-x402-hono ``` -------------------------------- ### Environment Variables (.env) Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/clients/chainlink-vrf-nft/README.md Create a .env file in the example directory with the client private key and provider URL. The wallet must have USDC and ETH for gas. ```dotenv # Wallet that pays the USDC (needs USDC and ETH for gas) PRIVATE_KEY=0xYOUR_CLIENT_PRIVATE_KEY # HTTP RPC endpoint for the blockchain network (e.g., Base Sepolia) # Must be accessible by all components PROVIDER_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY ``` -------------------------------- ### Install Core Package Source: https://github.com/b3-fun/anyspend-x402/blob/main/README.md Install the core @b3dotfun/anyspend-x402 package via npm. ```bash npm install @b3dotfun/anyspend-x402 ``` -------------------------------- ### Create exact payment requirements with USD price Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/servers/advanced/README.md Usage example showing how to create payment requirements with a USD price that automatically converts to USDC. ```python # USD price (automatically converts to USDC) payment_req = create_exact_payment_requirements( price="$0.001", network="base-sepolia", resource="https://api.example.com/weather", description="Weather data access" ) ``` -------------------------------- ### Create .env file with EVM_PRIVATE_KEY and SVM_PRIVATE_KEY Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/facilitator/README.md Required environment variables for the facilitator: EVM_PRIVATE_KEY for Ethereum and SVM_PRIVATE_KEY for Solana. ```env EVM_PRIVATE_KEY=0xYourPrivateKey SVM_PRIVATE_KEY=base58EncodedSolanaPrivateKey ``` -------------------------------- ### Install Solana Wallet Adapter Source: https://github.com/b3-fun/anyspend-x402/blob/main/README.md Install the Solana wallet adapter package for browser wallets. ```bash npm install @b3dotfun/anyspend-x402-solana-wallet-adapter ``` -------------------------------- ### Create exact payment requirements with specific token amount Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/servers/advanced/README.md Usage example showing how to create payment requirements with a specific token amount using TokenAmount and TokenAsset. ```python # Specific token amount payment_req = create_exact_payment_requirements( price=TokenAmount( amount="1000", asset=TokenAsset( address="0x036CbD53842c5426634e7929541eC2318f3dCF7e", decimals=6, eip712=EIP712Domain(name="USDC", version="2"), ), ), network="base-sepolia", resource="https://api.example.com/weather" ) ``` -------------------------------- ### Clone and Install x402 Java Source: https://github.com/b3-fun/anyspend-x402/blob/main/java/README.md Commands to clone the repository and install the library locally using Maven. ```bash # Clone the repository git clone https://github.com/coinbase/x402.git cd x402/java # Build and install to your local Maven repository mvn clean install ``` -------------------------------- ### Install dependencies and Electron Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/mcp-embedded-wallet/README.md Run this command to install dependencies and set up Electron for the x402-MCP project. ```bash pnpm install && node node_modules/electron/install.js ``` -------------------------------- ### getEipSupport usage example Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Example of fetching both EIP support flags for a token on Base and logging them. ```typescript const support = await client.getEipSupport( "base", "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" ); console.log("EIP-2612:", support.supportsEip2612); console.log("EIP-3009:", support.supportsEip3009); ``` -------------------------------- ### Example output of discovery script Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/discovery/README.md Shows the formatted output listing discovered resources with URL, type, update time, version, and accepted payment details. ```text Discovered X402 Resources: ======================== Resource 1: Resource URL: https://api.example.com/x402/endpoint Type: http Last Updated: 8/9/2025, 1:07:04 AM X402 Version: 1 Accepts: [ { "scheme": "exact", "network": "base-sepolia", "maxAmountRequired": "1000000", "resource": "https://api.example.com/x402/endpoint", "description": "Example protected endpoint", "mimeType": "application/json", "payTo": "0x1234...", "maxTimeoutSeconds": 300, "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e" } ] ------------------------ ``` -------------------------------- ### Quick Start Commands Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/README.md Commands to run the full test suite, development mode, and language filters. ```bash # Full suite pnpm test # Run all tests # Development mode (recommended) pnpm test -d # Test on testnet pnpm test -d -v # Test with verbose logging # Language filters pnpm test -d -ts # Test TypeScript implementations pnpm test -d -py # Test Python implementations pnpm test -d -go # Test Go implementations ``` -------------------------------- ### Simple approach with x402HttpxClient Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/httpx/README.md Uses the pre-configured x402HttpxClient to automatically handle payments. ```python from x402.clients import x402HttpxClient async with x402HttpxClient(account=account, base_url=base_url) as client: response = await client.get(endpoint_path) ``` -------------------------------- ### Client-side fetch with automatic payment Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/site/public/x402-whitepaper.pdf Install with npm install @x402/client. Configure the client with the user's wallet and use client.fetch to make API requests with automatic payment handling. ```javascript // Install with: npm install @x402/client import { x402Client } from '@x402/client'; import { connectWallet } from 'your-wallet-connector'; const client = new x402Client(); const wallet = await connectWallet(); // Configure the client with the user's wallet client.setWallet(wallet); // Make API requests with automatic payment handling try { const data = await client.fetch('https://api.example.com/premium-data'); console.log(data); // The premium data } catch (error) { console.error('Payment failed:', error); } ``` -------------------------------- ### Multi-protocol client test.config.json example Source: https://github.com/b3-fun/anyspend-x402/blob/main/e2e/clients/text-client-protocol.txt Declares a client supporting both EVM and SVM protocol families, requiring both EVM_PRIVATE_KEY and SVM_PRIVATE_KEY. ```json { "name": "universal-client", "type": "client", "language": "typescript", "protocolFamilies": ["evm", "svm"], "environment": { "required": ["EVM_PRIVATE_KEY", "SVM_PRIVATE_KEY", "RESOURCE_SERVER_URL", "ENDPOINT_PATH"], "optional": [] } } ``` -------------------------------- ### Install Dependencies with npm, yarn, pnpm, or bun Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/typescript/fullstack/farcaster-miniapp/README.md Install project dependencies using your preferred package manager. Choose one of the four commands. ```bash npm install ``` ```bash yarn install ``` ```bash pnpm install ``` ```bash bun install ``` -------------------------------- ### listEip2612Tokens usage example Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Example of listing all tokens with Permit support on Base and logging the total count. ```typescript // Get all tokens with Permit support on Base const permitTokens = await client.listEip2612Tokens("base"); console.log( `Found ${permitTokens.pagination.total} tokens with Permit support` ); ``` -------------------------------- ### getSupportedChains usage example Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Example of fetching the supported chains and logging each chain's full name, name, chain ID, and RPC configuration status. ```typescript const chains = await client.getSupportedChains(); chains.forEach((chain) => { console.log(`${chain.fullName} (${chain.name}): Chain ID ${chain.chainId}`); console.log(` RPC Configured: ${chain.rpcConfigured}`); }); ``` -------------------------------- ### supportsEip3009 usage example Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Example of checking EIP-3009 support for a token on Base and logging a message if supported. ```typescript const hasTransferAuth = await client.supportsEip3009( "base", "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" ); if (hasTransferAuth) { console.log("Token supports gasless transfers!"); } ``` -------------------------------- ### Requests Session Extensible Example with x402_http_adapter Source: https://github.com/b3-fun/anyspend-x402/blob/main/python/x402/README.md Create a requests.Session and mount the x402 HTTP adapter for both HTTP and HTTPS. Payment handling is automatic when making requests to protected endpoints. ```python import requests from eth_account import Account from x402.clients.requests import x402_http_adapter # Initialize account account = Account.from_key("your_private_key") # Create session and mount the x402 adapter session = requests.Session() adapter = x402_http_adapter(account) # Mount the adapter for both HTTP and HTTPS session.mount("http://", adapter) session.mount("https://", adapter) # Make request - payment handling is automatic response = session.get("https://api.example.com/protected-endpoint") print(response.content) ``` -------------------------------- ### Extensible approach with x402_payment_hooks Source: https://github.com/b3-fun/anyspend-x402/blob/main/examples/python/clients/httpx/README.md Uses x402_payment_hooks with your own httpx.AsyncClient to add payment handling. ```python from x402.clients import x402_payment_hooks import httpx async with httpx.AsyncClient(base_url=base_url) as client: client.event_hooks = x402_payment_hooks(account) response = await client.get(endpoint_path) ``` -------------------------------- ### Import createWalletAdapterSigner and TransactionSigner Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-solana-wallet-adapter/README.md Use this import to access the wallet adapter signer and the TransactionSigner type from the package. Requires the package to be installed. ```typescript import { createWalletAdapterSigner, type TransactionSigner, } from "@b3dotfun/anyspend-x402-solana-wallet-adapter"; ``` -------------------------------- ### listTokens usage example with pagination Source: https://github.com/b3-fun/anyspend-x402/blob/main/typescript/packages/x402-token-compat/README.md Example of listing the first 50 tokens on Base, logging pagination info and token symbols/names, then fetching the next page if available. ```typescript // Get first 50 tokens const response = await client.listTokens("base", { limit: 50 }); console.log(`Found ${response.pagination.total} total tokens`); console.log(`Returned ${response.pagination.returned} tokens`); response.tokens.forEach((token) => { console.log(`${token.symbol}: ${token.name}`); }); // Get next page if (response.pagination.hasMore) { const nextPage = await client.listTokens("base", { limit: 50, offset: 50, }); } ```