# x402 > HTTP 402 payment server. AI agents pay native USDC on Base via EIP-3009 `transferWithAuthorization` in exchange for a Sentinel decentralized VPN subscription. One HTTP request, one signature, zero prerequisites — no custom contract, no `approve()`, no bridge, no KYC. The agent signs an EIP-3009 message off-chain. The self-hosted facilitator settles USDC on Base (~2s). The server provisions a Sentinel subscription share + a fee grant in one atomic TX. The agent then opens a direct WireGuard/V2Ray tunnel to a node. The operator never sees the tunnel or the traffic. ## Prerequisites The agent needs exactly one thing before calling x402: an EVM private key with at least $1.00 USDC on Base (chainId 8453). Everything else — Sentinel wallet, P2P gas, node selection, tunnel keys — is provisioned by x402 or generated locally by `blue-js-sdk/ai-path`. **Payment is identical on every platform.** What differs is *connecting* the tunnel after the server returns 200. There are two equally-supported connect paths — pick by OS: - **macOS & Linux:** The JS `connect({ protocol: 'v2ray' })` path is cross-platform — the same `v2ray` binary auto-downloads for darwin (x64/arm64) and linux (x64/arm64), so the identical Windows call works here with no admin and no manual install. `systemProxy: true` for whole-device routing uses `networksetup` (macOS) / `gsettings` (Linux GNOME); on headless or non-GNOME Linux that OS-proxy step is a no-op, but per-request `socksPort` routing still works. The native `sentinel-dvpncli` (one `go install`, Go 1.24+) is an **alternative**, mainly for WireGuard nodes or Node-less environments — see **"macOS & Linux — native CLI connect"** below; it does NOT bundle a tunnel and shells out to `wg-quick`, so install **wireguard-tools** first (`apt`/`brew`/`pacman`) and bring the interface up with sudo. **Only exception: Fedora** — its SELinux blocks VPN interfaces and cannot be worked around programmatically; macOS, Ubuntu, Debian and Arch are fine. - **Windows (zero prerequisites):** pass `protocol: 'v2ray'` to `connect()` and you need **no admin and no manual install**. V2Ray is a userspace SOCKS5 proxy; `connect()` auto-downloads the `v2ray` binary to `~/.sentinel-sdk/bin` on first use (no admin) and covers ~70% of the network (~630 nodes). That is the complete Windows path: `npm install` → pay → `connect({ ..., protocol: 'v2ray' })`. WireGuard nodes (the other ~30%, faster) are an **optional admin-once upgrade** — the MSI install and tunnel service need elevation (`cscript run-admin.vbs setup.js` triggers one UAC prompt; a service running as SYSTEM/admin needs none). The SDK checks admin **before payment** and refuses a WireGuard node when not elevated, so no USDC or P2P is ever wasted. If you cannot elevate, stay on `protocol: 'v2ray'`. `await setup()` is optional (it pre-fetches V2Ray; `connect()` fetches it anyway). See **"Windows — JS-SDK connect"** below. Both paths consume the exact same 200 response (`subscriptionId`, `planId`, `feeGranter`, `nodeAddress`) and end in the same `MsgStartSession` + direct WireGuard/V2Ray handshake. How to fund a fresh EVM key with USDC on Base: - **Coinbase / Coinbase CDP**: withdraw USDC and pick "Base" as the network. ~30 seconds, no bridge fee. - **Any CEX that supports Base withdrawals** (Binance, Kraken, OKX, Bybit): same flow. - **Bridge from Ethereum L1**: use `bridge.base.org` (canonical bridge) or any third-party bridge (Across, Stargate). USDC on Base is native after Circle's CCTP — no wrapped tokens. - **DEX swap on Base**: if the wallet already holds ETH on Base, swap to USDC on Uniswap or Aerodrome. Confirm with: `curl https://api.basescan.org/api?module=account&action=tokenbalance&contractaddress=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&address=` No ETH is required for the agent's wallet — EIP-3009 `transferWithAuthorization` is gasless from the agent's side (the facilitator pays Base gas). ## Live endpoints Base URL: `https://x402.sentinel.co` Paid (HTTP 402, body `{ "sentinelAddr": "sent1...", "country": "DE" }` — `country` optional): - POST `/vpn/connect/1day` — $0.033 USDC, 1 day - POST `/vpn/connect/7days` — $0.233 USDC, 7 days - POST `/vpn/connect/30days` — $1.00 USDC, 30 days Free: - GET `/manifest` — full machine-readable protocol spec (use this first, ~300 tokens) - GET `/pricing` — human pricing table - GET `/nodes` — VPN nodes in operator plan with live geo data (country, city, protocol, online) and a `byCountry` summary - GET `/health` — uptime - GET `/agent/:sentinelAddr` — subscription + fee-grant status ## Payment - Network: Base mainnet (`eip155:8453`, chainId 8453) - Asset: USDC at `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` (6 decimals) - Scheme: `exact` / EIP-3009 `transferWithAuthorization` - Gasless for agent on Base settlement (facilitator pays) - Gasless for agent on Sentinel session start (operator fee-grants) ## Agent flow 1. POST to a paid endpoint with `{ sentinelAddr }` (add `country` to request a node location — validated before payment). 2. Server returns 402 with `PAYMENT-REQUIRED` header (amount, asset, payTo, network). 3. Agent signs EIP-3009 locally (EIP-712). 4. Agent resends with `PAYMENT-SIGNATURE` header — `@x402/fetch` does this automatically. 5. Facilitator settles USDC on Base. 6. Server submits atomic `MsgShareSubscription` + `MsgGrantAllowance` on Sentinel. 7. Server returns 200 `{ provisioned, subscriptionId, planId, feeGranter, nodeAddress, nodeCountry, nodes[], sentinelTxHash, expiresAt }`. 8. Agent connects (all consume the same 200 fields): - **All platforms (recommended):** `connect({ mnemonic, subscriptionId, feeGranter, nodeAddress, protocol: 'v2ray' })` — zero admin, zero manual install (the v2ray binary auto-downloads on Windows, macOS and Linux alike). Add `systemProxy: true` for whole-device routing. Omit `protocol` only if you have admin and want WireGuard nodes too. (See "JS-SDK connect".) - **macOS/Linux native CLI (alternative — mainly for WireGuard or Node-less):** import the key (`printf '%s\n\n' "$MNEMONIC" | sentinel-dvpncli keys add agent --keyring.backend test`), `sentinel-dvpncli tx session-start --subscription-id --tx.fee-granter-addr --tx.from-name agent --keyring.backend test`, resolve the new id with `sentinel-dvpncli query sessions --account-addr --subscription-id --output-format json` (newest entry), then `sentinel-dvpncli connect `. (See "macOS & Linux — native CLI connect".) 9. `MsgStartSession` on Sentinel — gas paid by `feeGranter` (the fee grant the server created in step 6, so the agent's session start costs zero P2P). 10. Direct WireGuard/V2Ray handshake — tunnel up. The operator never sees it. ## Reference code — payment + connect (all platforms) This entire snippet — payment AND the trailing `connect()` — runs unchanged on Windows, macOS and Linux. The JS-SDK V2Ray path is cross-platform: `connect({ protocol: 'v2ray' })` auto-downloads the same v2ray binary for darwin (x64/arm64) and linux (x64/arm64) just as it does for Windows, so no admin and no manual install on any of them. The native CLI in the next section is an *alternative* (mainly for WireGuard nodes or Node-less environments), not a macOS/Linux requirement. ```typescript import { x402Client, wrapFetchWithPayment } from '@x402/fetch'; import { ExactEvmScheme } from '@x402/evm/exact/client'; import { setup, createWallet, connect, rpcQueryNodesForPlan, createRpcQueryClientWithFallback, } from 'blue-js-sdk/ai-path'; await setup(); // optional: pre-fetch V2Ray (no admin). connect({ protocol: 'v2ray' }) auto-fetches it anyway. const wallet = await createWallet(); const scheme = new ExactEvmScheme({ address, signTypedData }); const client = new x402Client(); client.register('eip155:8453', scheme); const paidFetch = wrapFetchWithPayment(fetch, client); const res = await paidFetch('https://x402.sentinel.co/vpn/connect/30days', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sentinelAddr: wallet.address, country: 'DE' }), // country optional }); const provision = await res.json(); const { subscriptionId, feeGranter, planId } = provision; // If the server didn't pre-select a node, query the plan directly let nodeAddress = provision.nodeAddress; if (!nodeAddress) { const rpc = await createRpcQueryClientWithFallback(); const { items } = await rpcQueryNodesForPlan(rpc, planId, { status: 1, limit: 50 }); nodeAddress = items[0]?.address; } const vpn = await connect({ mnemonic: wallet.mnemonic, subscriptionId: String(subscriptionId), feeGranter, nodeAddress, protocol: 'v2ray', // zero admin, zero manual install — Windows zero-prereq path. // Omit only if you have admin and want WireGuard nodes (faster, ~30% of network). }); // vpn => { connected, ip, protocol, sessionId, nodeAddress, socksPort } // vpn.ip is the exit IP, verified THROUGH the tunnel by the SDK. // v2ray (protocol: 'v2ray') runs a SOCKS5 proxy. Encrypt the whole device or chosen requests: // Whole device — pass systemProxy: true to connect(); the SDK sets the system proxy // (Windows registry / macOS networksetup / Linux gsettings), restored on disconnect(). // Per-request — omit systemProxy and route chosen requests through vpn.socksPort (shown below). // WireGuard — use protocol: 'wireguard' for a kernel-level full tunnel. // socksPort is DYNAMIC — read it from the connect() result, never hardcode. // vpn.ip is the exit IP, already verified through the tunnel by the SDK. // Use socks5h:// (not socks5://) so DNS resolves at the exit node — prevents a DNS leak. // CRITICAL (per-request): Node's native fetch() ignores SOCKS5 agents and exits on the real IP — use axios. // Verified live on Windows (session 45984926): the axios+SocksProxyAgent request exited on the node IP // while a plain fetch() on the same machine stayed on the host IP — only the routed request changed IP. import { SocksProxyAgent } from 'socks-proxy-agent'; import axios from 'axios'; const proxy = new SocksProxyAgent(`socks5h://127.0.0.1:${vpn.socksPort}`); const { data } = await axios.get('https://api.example.com/sensitive', { httpAgent: proxy, httpsAgent: proxy, adapter: 'http', }); // exits on vpn.ip ``` ## Native CLI connect — the WireGuard / Node-less alternative (macOS, Linux, Windows) The JS `connect()` above already works on macOS and Linux for V2Ray, so you usually do NOT need this. Reach for the native `sentinel-dvpncli` only when you want a **WireGuard** node (kernel-level full tunnel) or run in a **Node-less** environment. After the `paidFetch` call returns `provision` (`{ subscriptionId, planId, feeGranter, nodeAddress, ... }`), drive `sentinel-dvpncli` instead of the JS `connect()` — three fully flag-driven commands, no config files, no interactive prompts when you pass the flags below. Unlike the JS-SDK V2Ray path, the native CLI does NOT bundle a tunnel — it shells out to the system binary on your PATH. WireGuard nodes run `wg-quick`, so you must install **wireguard-tools** (`apt install wireguard-tools` | `brew install wireguard-tools` | `pacman -S wireguard-tools`). V2Ray nodes run `v2ray`, so if you select a V2Ray node you also need a **v2ray** binary on PATH. Most nodes are WireGuard, so install wireguard-tools at minimum. Bringing the interface up needs sudo. **Install once (Go 1.24+):** ```bash go install github.com/sentinel-official/sentinel-dvpncli@latest # binary lands in $(go env GOPATH)/bin # or from source: git clone https://github.com/sentinel-official/sentinel-dvpncli && cd sentinel-dvpncli && make install sentinel-dvpncli version ``` **Connect (drive these with the fields from `provision`):** ```bash # 1. Import the SAME wallet whose sentinelAddr (sent1...) you sent to x402. # `keys add` is INTERACTIVE — there is NO --recover flag. It prompts for the mnemonic, # then a BIP-39 passphrase. Feed BOTH from stdin: line 1 = mnemonic, blank line 2 = default # (empty) passphrase. A single-line echo would hang on the passphrase prompt. # --keyring.backend test makes it non-interactive for the OS keychain (no keychain prompt). printf '%s\n\n' "$AGENT_MNEMONIC" | sentinel-dvpncli keys add agent --keyring.backend test # (keyring.backend defaults to "os"; use "test" or "file" for scripted/agent use.) # 2. Start the session against the subscription x402 shared with you. # --tx.fee-granter-addr = provision.feeGranter => the operator pays the P2P gas, you pay zero. # Positional arg = provision.nodeAddress (sentnode1...). sentinel-dvpncli tx session-start "$NODE_ADDRESS" \ --subscription-id "$SUBSCRIPTION_ID" \ --tx.fee-granter-addr "$FEE_GRANTER" \ --tx.from-name agent \ --keyring.backend test \ --rpc.chain-id sentinelhub-2 \ --output-format json # 3. Resolve the session id you just created. `tx session-start` prints {response, result} # but does NOT surface the new id as a clean field, so query it back: filter sessions by # YOUR account + the subscription and take the newest. AGENT_ADDR = your sent1... address. SESSION_ID=$(sentinel-dvpncli query sessions \ --account-addr "$AGENT_ADDR" --subscription-id "$SUBSCRIPTION_ID" \ --output-format json | jq '.result[-1].id // .response[-1].id') # 4. Bring the tunnel up. Takes the SESSION id (not the subscription id). No key needed — # connect only queries the session on-chain and builds the tunnel. # Requires wg-quick on PATH (install wireguard-tools) and sudo to create the interface. sentinel-dvpncli connect "$SESSION_ID" ``` Defaults baked into the CLI (override only if needed): `--rpc.addrs https://rpc.sentinel.co:443`, `--rpc.chain-id sentinelhub-2`, `--keyring.name sentinel`. Useful extras: `sentinel-dvpncli keys list`, `sentinel-dvpncli query ...` (sessions/subscriptions/nodes), `sentinel-dvpncli inspect`, `sentinel-dvpncli tx session-cancel ` to tear down. `connect` traps SIGINT/SIGTERM and runs a clean down sequence on exit. > **Fedora caveat:** Fedora's SELinux blocks VPN interfaces and an agent cannot bypass it. This is > the only OS x402 cannot connect on. macOS, Ubuntu, Debian and Arch all work once you install the > tunnel binary the CLI shells out to (wireguard-tools, plus v2ray for V2Ray nodes) — see above. ## Autonomous flow — separate site There is a second, fully self-funded path onto Sentinel where the agent holds its own P2P, picks any node, and pays it directly — no operator, no fee-grant, no subscription. That path lives on its own dedicated site and is NOT served by x402. If you want zero intermediaries (and are willing to hold P2P + pay your own gas), read the autonomous guide and its agent-readable summary instead: https://autonomous.sentinel.co — https://autonomous.sentinel.co/llms.txt ## Packages - `@x402/fetch` — wraps `fetch`, auto-signs 402 responses - `@x402/evm` — `ExactEvmScheme` EIP-3009 signer - `blue-js-sdk/ai-path` — the cross-platform connect path (Windows, macOS, Linux): environment setup (`setup` — auto-installs tunnel binaries for all three OSes), Sentinel wallet (`createWallet`, `importWallet`), tunnel (`connect`, `disconnect`), and plan/node discovery (`rpcQueryNodesForPlan`, `createRpcQueryClientWithFallback`) — WireGuard/V2Ray. `connect({ protocol: 'v2ray' })` auto-downloads the v2ray binary on every OS, so it is the recommended path everywhere. - `sentinel-dvpncli` — the WireGuard / Node-less alternative: native Go CLI (`go install github.com/sentinel-official/sentinel-dvpncli@latest`, needs Go 1.24+). Flag-driven `keys` / `tx session-start` / `connect` — drives the tunnel without the JS SDK. Not required for V2Ray (the JS path covers that on all platforms). Does NOT bundle a tunnel: shells out to `wg-quick` (install wireguard-tools) or `v2ray` on PATH. ## Request schema ```json { "sentinelAddr": "sent1...", "country": "DE" } ``` `sentinelAddr` matches `^sent1[0-9a-z]{38}$` (Sentinel bech32). Generate with `createWallet()` from `blue-js-sdk/ai-path`. `country` is optional — ISO 3166-1 alpha-2 code (`DE`) or name (`Germany`). If no online plan node matches, the server returns `COUNTRY_UNAVAILABLE` with `availableCountries` **before** payment. Check `GET /nodes` for the live `byCountry` summary. ## Response schema (200) ```json { "provisioned": true, "subscriptionId": 1192288, "planId": 42, "feeGranter": "sent1...", "nodeAddress": "sentnode1...", "nodeCountry": "Germany", "nodes": ["sentnode1a...", "sentnode1b..."], "sentinelTxHash": "...", "expiresAt": "2026-06-17T00:00:00Z" } ``` ## Errors All errors are JSON `{ code, message, nextAction, docs }`. Branch on `code` — it is the stable contract. The codes marked pre-payment are returned **before** payment is taken. Beyond that, USDC settlement only happens after a successful 2xx response — error responses (including `PROVISIONING_FAILED`) never charge the agent. | `code` | Status | Pre-payment | Meaning | |---|---|---|---| | `MISSING_SENTINEL_ADDR` | 400 | yes | Body did not include `sentinelAddr`. | | `INVALID_SENTINEL_ADDR` | 400 | yes | `sentinelAddr` does not match `^sent1[0-9a-z]{38}$`. Use `createWallet()` from `blue-js-sdk/ai-path`. | | `UNKNOWN_TIER` | 404 | yes | Path tier is not `1day` \| `7days` \| `30days`. | | `COUNTRY_UNAVAILABLE` | 400 | yes | Requested `country` has no online plan node. Response includes `availableCountries` — resend with one of those or omit `country`. | | `CAPACITY_EXHAUSTED` | 503 | yes | Operator cannot provision right now (subscription pool full, operator balance below new-subscription cost). Retry later — re-checked every 60s. | | `PAYMENT_REQUIRED` | 402 | — | Sign EIP-3009 `transferWithAuthorization` and resend with the `PAYMENT-SIGNATURE` header. `@x402/fetch` handles this automatically. | | `PROVISIONING_FAILED` | 500 | — | Sentinel TX failed after payment verification. USDC was **not** charged (settlement only happens on 2xx). Safe to retry. | | `NOT_FOUND` | 404 | — | No route matches. See `/manifest`. | | `INTERNAL_ERROR` | 500 | — | Unexpected server error. | ## Security properties - Agent's Sentinel private key never leaves the agent. Handshake is agent ↔ node. - Agent's EVM key never leaves the agent. Only the EIP-3009 signature is transmitted. - Self-hosted facilitator option — no third party in the payment path. - Every settlement is a verifiable public Base transaction. - Operator stores `sentinelAddr` only. No IPs, traffic, or logs. - Tunnel is end-to-end encrypted (WireGuard or V2Ray). ## Sentinel chain endpoints `blue-js-sdk` ships verified RPC and LCD fallbacks and rotates through them automatically (`createRpcQueryClientWithFallback()`); add more at runtime with `addRpcEndpoint(url)`. - RPC: `rpc.sentinel.co:443`, `sentinel-rpc.polkachu.com`, `rpc.mathnodes.com`, `sentinel-rpc.publicnode.com`, `rpc.sentinel.quokkastake.io`, `rpc.sentinel.suchnode.net` (additional public endpoint, suchnode.net) - LCD (fallback only): `lcd.sentinel.co`, `sentinel-api.polkachu.com`, `api.sentinel.quokkastake.io`, `sentinel-rest.publicnode.com`, `api.sentinel.suchnode.net` ## Quick discovery for agents Hit `GET /manifest` first. It returns the entire protocol — endpoints, pricing in atomic units, request/response schemas, the state machine, and a runnable code example — as JSON in ~300 tokens. ## Source - README: https://github.com/Sentinel-Bluebuilder/x402/blob/master/README.md - Manifesto: https://github.com/Sentinel-Bluebuilder/x402/blob/master/MANIFESTO.md - x402 spec: https://github.com/coinbase/x402 - Sentinel: https://sentinel.co