### Setup and run the sign-in-with-x client Source: https://github.com/x402-foundation/x402/blob/main/examples/python/clients/sign-in-with-x/README.md Setup and run the client example. Copy the environment file, install dependencies, start the SIWX server, then run the client. Requires Python 3.10+, uv, and at least one private key (EVM or SVM). ```bash cp .env-local .env ``` ```bash uv sync --reinstall-package x402 ``` ```bash cd ../../servers/sign-in-with-x uv sync --reinstall-package x402 uv run python main.py ``` ```bash cd ../../clients/sign-in-with-x uv run python main.py ``` -------------------------------- ### Quick Start: Setup and Run Example Source: https://github.com/x402-foundation/x402/blob/main/examples/python/README.md Commands to set up and run an example client. Copy .env-local to .env, edit with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY, sync dependencies, and run main.py. ```bash cd clients/httpx cp .env-local .env # Edit .env with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY uv sync --reinstall-package x402 uv run python main.py ``` -------------------------------- ### Setup and run the Next.js batch-settlement Redis example Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/fullstack/next-batch-settlement-redis/README.md Install dependencies, build the project, and start the development server from the examples/typescript directory. The first command installs and builds the monorepo, then changes into the example directory; the second starts the Next.js dev server. ```bash pnpm install && pnpm build cd fullstack/next-batch-settlement-redis ``` ```bash pnpm dev ``` -------------------------------- ### Setup commands to install and build from typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/builder-code/README.md Commands to navigate to the typescript examples root, install dependencies, build, and change to the builder-code client directory. ```bash cd ../../ pnpm install && pnpm build cd clients/builder-code ``` -------------------------------- ### Setup and Run Commands Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/offer-receipt/README.md Commands to install dependencies, copy the environment file, and run the example. Configuration requires EVM_PRIVATE_KEY, SVM_PRIVATE_KEY, RESOURCE_SERVER_URL, and ENDPOINT_PATH environment variables. ```bash cd ../../ pnpm install && pnpm build cd clients/offer-receipt ``` ```bash cp .env-local .env ``` ```bash pnpm start ``` -------------------------------- ### Setup Commands for Custom x402 Client Source: https://github.com/x402-foundation/x402/blob/main/examples/go/clients/custom/README.md Setup commands for the custom client: copy the environment template, install dependencies, and run the example. ```bash cp .env-example .env ``` ```bash go mod download ``` ```bash go run . ``` -------------------------------- ### Run the client Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/fetch/README.md Starts the example client with pnpm start. ```bash pnpm start ``` -------------------------------- ### Install and run server Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/servers/offer-receipt/README.md Builds and starts the offer-receipt server after installing dependencies. ```bash cd ../../ pnpm install && pnpm build cd servers/offer-receipt pnpm dev ``` -------------------------------- ### Install and build from typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/servers/sign-in-with-x/README.md Navigates to the typescript examples root and installs dependencies with pnpm, then builds the project. ```bash cd ../../ pnpm install && pnpm build cd servers/sign-in-with-x ``` -------------------------------- ### Install and build packages from examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/axios/README.md Run from the typescript examples root to install dependencies and build all packages before running the client. ```bash cd ../../ pnpm install && pnpm build cd clients/axios ``` -------------------------------- ### Setup: copy .env and install dependencies Source: https://github.com/x402-foundation/x402/blob/main/examples/python/clients/httpx/README.md Setup commands: copy the environment template and install dependencies. Requires a .env file with private keys and server configuration. ```bash cp .env-local .env ``` ```bash uv sync --reinstall-package x402 ``` -------------------------------- ### Setup commands for payment-identifier client Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/payment-identifier/README.md Commands to install dependencies, build packages, copy environment file, start the server, and run the client. ```bash cd ../../ pnpm install && pnpm build cd clients/payment-identifier ``` ```bash cp .env-local .env ``` ```bash cd ../../servers/payment-identifier pnpm dev ``` ```bash pnpm dev ``` -------------------------------- ### Install and Build from Typescript Examples Root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/sign-in-with-x/README.md Installs dependencies and builds the project from the typescript examples root, then changes to the sign-in-with-x client directory. ```bash cd ../../ pnpm install && pnpm build cd clients/sign-in-with-x ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/fullstack/miniapp/README.md Run these commands from the typescript examples root to install dependencies and build all packages, then navigate to the miniapp directory. ```bash cd ../../ pnpm install && pnpm build cd fullstack/miniapp ``` -------------------------------- ### Setup commands for auth-capture client Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/auth-capture/README.md Commands to copy the environment file, install dependencies, build the project, and start the example. Requires Node.js v20+, pnpm v10, and a running auth-capture server. ```bash cp .env-local .env # Fill EVM_PRIVATE_KEY (and override RESOURCE_SERVER_URL if needed) cd ../../.. pnpm install && pnpm build cd examples/clients/auth-capture pnpm start ``` -------------------------------- ### Test the server with example client Source: https://github.com/x402-foundation/x402/blob/main/examples/python/servers/builder-code/README.md Commands to set up and run the example client for testing the server. ```bash cd ../../clients/builder-code cp .env-local .env # Fill in EVM_PRIVATE_KEY and CLIENT_BUILDER_CODE uv sync --reinstall-package x402 uv run python main.py ``` -------------------------------- ### Install dependencies and run Go example Source: https://github.com/x402-foundation/x402/blob/main/examples/go/clients/payment-identifier/README.md Commands to download dependencies and run the Go program. ```bash go mod download go run main.go ``` -------------------------------- ### Install x402 Go package Source: https://github.com/x402-foundation/x402/blob/main/README.md Install the x402 Go package. Use this to get started with x402 in Go. ```shell go get github.com/x402-foundation/x402/go/v2 ``` -------------------------------- ### Install x402 Python package Source: https://github.com/x402-foundation/x402/blob/main/README.md Install the x402 Python package. Use this to get started with x402 in Python. ```shell pip install x402 ``` -------------------------------- ### Setup commands Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/servers/payment-identifier/README.md Commands to copy environment file, install dependencies, build, and run the server. ```bash cp .env-local .env ``` ```bash cd ../../ pnpm install && pnpm build cd servers/payment-identifier ``` ```bash pnpm dev ``` -------------------------------- ### Run server and client examples Source: https://github.com/x402-foundation/x402/blob/main/examples/go/clients/sign-in-with-x/README.md Start the matching server example first, then run the client. The server requires EVM_ADDRESS and FACILITATOR_URL environment variables; the client requires EVM_PRIVATE_KEY. ```sh cd ../../servers/sign-in-with-x EVM_ADDRESS=0x... FACILITATOR_URL=https://x402.org/facilitator go run . ``` ```sh EVM_PRIVATE_KEY=0x... go run . ``` -------------------------------- ### Setup and run the Upto facilitator Source: https://github.com/x402-foundation/x402/blob/main/examples/go/facilitator/upto/README.md Sets up the facilitator from the example environment file, sets the SVM private key, and runs the service. The default listen address is http://localhost:4022, overridable with the PORT environment variable. ```bash cp .env-example .env # set SVM_PRIVATE_KEY go run . ``` -------------------------------- ### Quick Start: Express with x402 paymentMiddleware Source: https://github.com/x402-foundation/x402/blob/main/typescript/packages/http/express/README.md Quick start example showing how to set up an Express app with x402 payment middleware. It creates a facilitator client, registers an ExactEvmScheme for the eip155:84532 network, and protects a GET route with a $0.10 payment requirement. ```typescript import express from "express"; import { paymentMiddleware, x402ResourceServer } from "@x402/express"; import { ExactEvmScheme } from "@x402/evm/exact/server"; import { HTTPFacilitatorClient } from "@x402/core/server"; const app = express(); const facilitatorClient = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" }); const resourceServer = new x402ResourceServer(facilitatorClient) .register("eip155:84532", new ExactEvmScheme()); // Apply the payment middleware with your configuration app.use( paymentMiddleware( { "GET /protected-route": { accepts: { scheme: "exact", price: "$0.10", network: "eip155:84532", payTo: "0xYourAddress", }, description: "Access to premium content", }, }, resourceServer, ), ); // Implement your protected route app.get("/protected-route", (req, res) => { res.json({ message: "This content is behind a paywall" }); }); app.listen(3000); ``` -------------------------------- ### Setup Environment and Dependencies Source: https://github.com/x402-foundation/x402/blob/main/examples/python/servers/flask/README.md Commands to configure the environment, install dependencies, and run the server. ```bash cp .env-local .env ``` ```bash uv sync --reinstall-package x402 ``` ```bash uv run python main.py ``` -------------------------------- ### GET /supported Response Example Source: https://github.com/x402-foundation/x402/blob/main/go/FACILITATOR.md Example JSON response from the GET /supported endpoint, showing the supported networks and schemes. In this example, it lists an exact scheme on the eip155:84532 network. ```json { "kinds": [ { "x402Version": 2, "scheme": "exact", "network": "eip155:84532" } ] } ``` -------------------------------- ### Run httpx async example Source: https://github.com/x402-foundation/x402/blob/main/examples/python/clients/README.md Commands to set up and run the httpx example. Copy the .env-local file to .env, edit it with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY, then sync and run the main.py script. ```bash cd httpx cp .env-local .env # Edit .env with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY uv sync --reinstall-package x402 uv run python main.py ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/facilitator/builder-code/README.md Installs dependencies and builds all packages from the typescript examples root directory. ```bash cd ../../ pnpm install && pnpm build cd facilitator/builder-code ``` -------------------------------- ### Install and build all packages from the typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/fullstack/next/README.md Installs dependencies and builds all packages from the typescript examples root, then changes to the fullstack/next directory. ```bash cd ../../ pnpm install && pnpm build cd fullstack/next ``` -------------------------------- ### Configure and use x402 HTTP client Source: https://github.com/x402-foundation/x402/blob/main/examples/go/clients/http/README.md Example showing how to initialize a signer, configure the x402 client with the builder pattern, wrap the standard HTTP client, and perform a request. ```go import ( x402 "github.com/x402-foundation/x402/go/v2" x402http "github.com/x402-foundation/x402/go/v2/http" evm "github.com/x402-foundation/x402/go/v2/mechanisms/evm/exact/client" evmsigners "github.com/x402-foundation/x402/go/v2/signers/evm" ) // Create signer signer, err := evmsigners.NewClientSignerFromPrivateKey(os.Getenv("EVM_PRIVATE_KEY")) // Configure client with builder pattern. // Newx402Client() enables default spend controls: recognized pegged assets only, capped at $1 USD. // Registers exact, upto, and auth-capture EVM schemes (plus SVM when configured). client := x402.Newx402Client(). Register("eip155:*", evm.NewExactEvmScheme(signer)). Register("eip155:*", authcaptureclient.NewAuthCaptureEvmScheme(signer)) // Optional: raise the cap or opt into non-default tokens // client.SetSpendControls(x402.SpendControls{MaxAmountPerPayment: "$5"}) // client.DisableSpendControls() // disable all spend controls (any asset, no caps) // Wrap HTTP client with payment handling httpClient := x402http.WrapHTTPClientWithPayment( http.DefaultClient, x402http.Newx402HTTPClient(client), ) // Make request to paid endpoint (payment is handled automatically) resp, err := httpClient.Get("http://localhost:4021/weather") body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) ``` -------------------------------- ### Run example clients (fetch and axios) Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/servers/express/README.md Run the example clients to test the server. The fetch client and axios client are separate commands; each requires a .env file to be set up before running. ```bash cd ../clients/fetch # Ensure .env is setup pnpm dev ``` ```bash cd ../clients/axios # Ensure .env is setup pnpm dev ``` -------------------------------- ### Install and build packages from typescript examples root Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/fetch/README.md Commands to install dependencies and build all packages from the typescript examples root, then change to the fetch client directory. ```bash cd ../../ pnpm install && pnpm build cd clients/fetch ``` -------------------------------- ### Set up v2 implementations with pnpm setup Source: https://github.com/x402-foundation/x402/blob/main/e2e/README.md Sets up only the v2 implementations. Use this if you do not need legacy (v1) setup. ```bash pnpm setup ``` -------------------------------- ### Start MCP server (Go, TypeScript, or Python) Source: https://github.com/x402-foundation/x402/blob/main/examples/go/clients/mcp-chatbot/README.md Commands to start an MCP server in Go, TypeScript, or Python. The Go server is started from the examples/go/servers/mcp directory, the TypeScript server from the typescript examples, and the Python server from the python examples. ```bash # Go server cd ../../servers/mcp go run . simple ``` ```bash # Or TypeScript server cd ../../../../typescript/examples/servers/mcp pnpm dev ``` ```bash # Or Python server cd ../../../../python/examples/servers/mcp python main.py simple ``` -------------------------------- ### Setup and run batch-settlement client Source: https://github.com/x402-foundation/x402/blob/main/examples/typescript/clients/batch-settlement/README.md Sets up and runs the batch-settlement client. Copies the local environment file, installs dependencies, builds the project, and starts the client. Requires Node.js v20+, pnpm v10, a running batch-settlement server, and a funded EVM_PRIVATE_KEY. ```bash cp .env-local .env # fill EVM_PRIVATE_KEY (and optionally EVM_VOUCHER_SIGNER_PRIVATE_KEY) cd ../../ pnpm install && pnpm build cd clients/batch-settlement pnpm start ```