diff --git a/changelog/index.md b/changelog/index.md index 9b2d440c..b03016ba 100644 --- a/changelog/index.md +++ b/changelog/index.md @@ -7,6 +7,21 @@ description: 'Product updates and announcements for BANK OF AI — all products, Product updates and announcements for BANK OF AI. +
+
Jul 30, 2026
+
+ +### x402 CLI v1.0.2 · Catalog — Base support + +
New Releasex402Base
+ +- **Base is live in the CLI** — `eip155:8453` and `eip155:84532` both support USDC. The service catalog currently publishes Base Mainnet routes on `eip155:8453` only. Base settles under `exact` using EIP-3009 authorization instead of Permit2. +- **Agent Wallet is now the CLI's default payer** — `pay` signs with your active wallet, so no private key in an environment variable. With wallets configured but none active, the CLI stops before signing rather than choosing for you. [Details](./x402/) +- Paid requests no longer follow HTTP redirects, keeping `PAYMENT-SIGNATURE` from reaching another origin. + +
+
+
Jul 21, 2026
@@ -25,6 +40,20 @@ Product updates and announcements for BANK OF AI.
+
+
Jul 20, 2026
+
+ +### x402 CLI v1.0.1 · Catalog + +
New Releasex402TRON
+ +- **x402 CLI v1.0.1** — TRON **GasFree** payments (`exact_gasfree`, no TRX needed), canonical CAIP-2 network IDs (legacy `tron:nile` rejected), and `settled` vs `delivered` reporting. Built on x402 SDK 1.0.1. [Details](./x402/) +- **x402 Catalog** — routes now support `exact_gasfree` on TRON; canonical CAIP-2 required; legacy `fee` / `feeConfig` fields dropped. [Details](./x402/) + +
+
+
Jul 17, 2026
diff --git a/changelog/x402.md b/changelog/x402.md index b5538e79..976e016e 100644 --- a/changelog/x402.md +++ b/changelog/x402.md @@ -5,7 +5,78 @@ description: 'Release notes for the x402 payment protocol, SDK, and CLI.' # x402 Payment Protocol -Release notes for the x402 protocol, SDK, and [CLI](../x402/cli/). +Release notes for the x402 protocol, SDK, and [CLI](/x402/cli/). + +
+
Jul 30, 2026
+
+ +### x402 CLI v1.0.2 — Base USDC & Agent Wallet + +
New ReleaseCLIBase
+ +- **Base support** — `eip155:8453` (Mainnet) and `eip155:84532` (Sepolia), both with USDC, plus the `base-mainnet` / `base-sepolia` aliases. Base settles through the standard `exact` scheme using **EIP-3009** authorization rather than Permit2. Supply your own RPC in production via `--rpc-url` or `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532`. +- **Agent Wallet is now the default payer** — `pay` resolves your active [Agent Wallet](/Agent-Wallet/Intro/) and delegates signing, so no private key sits in an environment variable. If wallets are configured but none is active, the CLI **stops before signing** instead of picking one for you. Select explicitly with `--wallet-id` / `AGENT_WALLET_ID`, or point at another directory with `AGENT_WALLET_DIR`. Private keys are now a development/CI override only. +- **Redirects are no longer followed** on paid requests, so `PAYMENT-SIGNATURE` can't be forwarded to another origin. +- **EVM balance pre-check** — the CLI verifies the payer's token balance before signing and returns the resolved wallet ID, address, and raw balance. +- New: `pay --asset` / `--decimals`, `serve --valid-for-seconds` (default `300`), and `roundtrip --json` emitting one document with separate `serve` and `pay` results. +- New wallet error codes: `WALLET_PASSWORD_REQUIRED`, `WALLET_DECRYPTION_FAILED`, `WALLET_CONFIG_CORRUPT`, `WALLET_NETWORK_ERROR`. + +👉 [x402 CLI docs](/x402/cli/) + +
+
+ +
+
Jul 30, 2026
+
+ +### x402 Catalog — Base routes + +
UpdateCatalogBase
+ +- Published **Base Mainnet catalog routes** on `eip155:8453`, with payment guides and code examples. Base Sepolia remains available in the CLI but is not published in the service catalog. +- `assetTransferMethod` now accepts **`eip3009`** alongside `permit2` — Base USDC routes use `eip3009`. + +👉 [API Catalog reference](/x402/api-catalog/reference/) + +
+
+ +
+
Jul 20, 2026
+
+ +### x402 CLI v1.0.1 + +
New ReleaseCLITRON
+ +- **GasFree payments (`exact_gasfree`) on TRON** — a relayer pays the network energy and deducts its fee from the payment token, so the payer needs no TRX. New flags: `--scheme exact_gasfree`, `--max-gasfree-fee`, `--max-gasfree-fee-raw`, `--gasfree-api-url`. +- **Canonical CAIP-2 network IDs** — `tron:0x2b6653dc` (Mainnet), `tron:0xcd8690dc` (Nile), `tron:0x94a9059e` (Shasta). Legacy identifiers like `tron:nile` / `tron:mainnet` are now **rejected** — the CLI tells you the canonical ID to use. +- **Settlement reporting** — paid responses distinguish `settled` (payment cleared on-chain) from `delivered` (upstream HTTP response succeeded). +- Built on x402 SDK 1.0.1. + +👉 [x402 CLI docs](/x402/cli/) + +
+
+ +
+
Jul 20, 2026
+
+ +### x402 Catalog — GasFree routes & CAIP-2 + +
UpdateCatalog
+ +- Catalog routes now support **`exact_gasfree`** on TRON, alongside `exact` + Permit2. +- Network IDs must be **canonical CAIP-2**; legacy TRON aliases like `tron:nile` are rejected by schema validation. +- With x402 SDK 1.0.1, GasFree cost is estimated client-side — routes must no longer publish the legacy `fee` / `feeConfig` fields. + +👉 [API Catalog reference](/x402/api-catalog/reference/) + +
+
Jul 15, 2026
@@ -24,7 +95,7 @@ First stable release of `@bankofai/x402-cli` — a TypeScript command-line clien - Built on the published `@bankofai/x402-core` / `x402-evm` / `x402-tron` SDK 1.0 packages; `scheme=exact` with Permit2 - Networks: TRON (`tron:mainnet` / `tron:nile` / `tron:shasta`) and BSC (`eip155:56` / `eip155:97`) -👉 Get started: [x402 CLI Quick Start](../x402/cli/quickstart/) +👉 Get started: [x402 CLI Quick Start](/x402/cli/quickstart/)
diff --git a/docs/Agent-Wallet/Developer/CLI-Reference.md b/docs/Agent-Wallet/Developer/CLI-Reference.md index 6dbb65f8..396c8442 100644 --- a/docs/Agent-Wallet/Developer/CLI-Reference.md +++ b/docs/Agent-Wallet/Developer/CLI-Reference.md @@ -58,6 +58,33 @@ agent-wallet start -p Abc12345! -k your-private-key-hex agent-wallet start -p Abc12345! -m "word1 word2 word3 ..." ``` +#### Skip the prompts: name the wallet type directly + +`start` and `add` also take the wallet type as a subcommand. That form asks nothing, which is what you want in CI or any background service: + +```bash +agent-wallet start local_secure -p Abc12345! -g # encrypted, generate a new key +agent-wallet start raw_secret -k your-private-key # plaintext, dev only +agent-wallet start privy --app-id --app-secret --privy-wallet-id +``` + +`add` works the same way (`add local_secure` / `add raw_secret` / `add privy`) for a second wallet. + +| Option | Applies to | Description | +| :--- | :--- | :--- | +| `-w, --wallet-id ` | all | Wallet ID to create | +| `-g, --generate` | `local_secure` | Generate a new random key | +| `-k, --private-key ` | `local_secure`, `raw_secret` | Import a private key | +| `-m, --mnemonic ` | `local_secure`, `raw_secret` | Import a mnemonic | +| `--mnemonic-index ` | `local_secure`, `raw_secret` | Account index when deriving from the mnemonic | +| `-p, --password ` | `local_secure` | Master password | +| `--app-id` / `--app-secret` / `--privy-wallet-id` | `privy` | Privy app credentials and wallet ID | +| `-d, --dir ` | all | Secrets directory (default `~/.agent-wallet`) | +| `--save-runtime-secrets` | all | Persist the password to `runtime_secrets.json` | +| `--override` | `start` only | Overwrite an existing setup | + +Run `agent-wallet start local_secure --help` or `agent-wallet add privy --help` for the exact options of one mode. + ### `agent-wallet sign` (Core Signing Operations) Every `sign` subcommand requires `--network` / `-n` to specify the chain. diff --git a/docs/Agent-Wallet/Developer/SDK-Guide.md b/docs/Agent-Wallet/Developer/SDK-Guide.md index 0358ad39..68e77a43 100644 --- a/docs/Agent-Wallet/Developer/SDK-Guide.md +++ b/docs/Agent-Wallet/Developer/SDK-Guide.md @@ -195,6 +195,10 @@ If both a password and a private key exist in your environment variables, the SD | `AGENT_WALLET_MNEMONIC` | Plaintext mnemonic phrase | ⚠️ Static Injection | Choose one (with private key) | | `AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX` | BIP-44 derivation index (default `0`) | ⚠️ Static Injection | Optional | +:::note Legacy variable names +The SDK still accepts the older `TRON_PRIVATE_KEY`, `TRON_MNEMONIC`, and `TRON_ACCOUNT_INDEX` variables, which map to `AGENT_WALLET_PRIVATE_KEY`, `AGENT_WALLET_MNEMONIC`, and `AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX`. They work on EVM networks too, despite the name. Prefer the `AGENT_WALLET_*` names in new setups. +::: + --- ## Usage Examples diff --git a/docs/x402/AGENTS.md b/docs/x402/AGENTS.md index a96707c7..115d60a0 100644 --- a/docs/x402/AGENTS.md +++ b/docs/x402/AGENTS.md @@ -83,6 +83,15 @@ Documentation must reflect code changes immediately. Follow these dependency map - **Node Access**: Must connect to EVM-compatible JSON-RPC endpoints. - **Test Example**: BSC Testnet mock USDT address — `0x337610d27c682E347C9cD60BD4b3b107C9d34dDd`. + + + +- **Network Identifier**: Base Mainnet must use canonical CAIP-2 ID `eip155:8453`. +- **Settlement Asset**: Use official Base USDC at `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`. +- **Payment Scheme**: Use `exact` with EIP-3009 authorization; do not describe Base USDC as Permit2. +- **Address Format**: Payout and token addresses use EVM hexadecimal (`0x`) format. +- **Catalog Scope**: Public catalog examples use Base Mainnet only. Base Sepolia (`eip155:84532`) may appear only in explicit CLI/SDK testing documentation. + diff --git a/docs/x402/api-catalog/get-started.md b/docs/x402/api-catalog/get-started.md index 76c0ca1b..01129f4b 100644 --- a/docs/x402/api-catalog/get-started.md +++ b/docs/x402/api-catalog/get-started.md @@ -12,7 +12,7 @@ Two steps and under 3 minutes to plug your Agent into the whole catalog: install ## Step 1: Install the Agent Wallet -Run the command below to install a local wallet that manages stablecoins on TRON & BNB Chain. Every paid call your Agent makes from now on is signed locally by this wallet. +Run the command below to install a local wallet that manages stablecoins on TRON, BNB Chain, and Base. Every paid call your Agent makes from now on is signed locally by this wallet. ```bash npm i -g @bankofai/agent-wallet @@ -73,8 +73,8 @@ x402-cli pay 'https://x402-gateway.bankofai.io/providers//' \ | Flag | Purpose | |---|---| | `--method` | HTTP method (defaults to `GET`) | -| `--network` | CAIP-2 payment chain, e.g. `tron:0x2b6653dc`, `eip155:56` | -| `--token` | Settlement token, e.g. `USDT` | +| `--network` | CAIP-2 payment chain, e.g. `tron:0x2b6653dc`, `eip155:56`, `eip155:8453` | +| `--token` | Settlement token, e.g. `USDT` or Base Mainnet `USDC` | | `--scheme` | x402 payment scheme declared by the route, e.g. `exact` | | `--max-amount` | Spend ceiling in USD; the call aborts if the quote exceeds it | | `--header` / `--body` | Request headers and body for the upstream call | diff --git a/docs/x402/api-catalog/index.md b/docs/x402/api-catalog/index.md index 3deac04c..7f8b48aa 100644 --- a/docs/x402/api-catalog/index.md +++ b/docs/x402/api-catalog/index.md @@ -8,7 +8,7 @@ description: BANK OF AI's wallet-native service catalog — where AI Agents disc Traditional API onboarding is designed for humans: create an account, request an API key, link a credit card, subscribe monthly. When an AI Agent wants to call an API on its own, it fails at the very first step — it has no email, no credit card, and it shouldn't be holding a pile of secret keys for you anyway. -The **API Catalog** is BANK OF AI's wallet-native service catalog. AI Agents discover services here, call them by name, and pay per call — every call settles on-chain via x402. No accounts, no API keys: **your wallet is your identity**. The catalog covers both TRON and BNB Chain. +The **API Catalog** is BANK OF AI's wallet-native service catalog. AI Agents discover services here, call them by name, and pay per call — every call settles on-chain via x402. No accounts, no API keys: **your wallet is your identity**. The catalog covers TRON, BNB Chain, and Base Mainnet. ## What it solves @@ -41,7 +41,7 @@ Three consumers share the same data: ## What's in the catalog -The first live services cover token creation plus DeFi market data and on-chain security — all settling across TRON and BNB Chain, with more being added over time: +The first live services cover token creation plus DeFi market data and on-chain security, with routes settling across TRON, BNB Chain, and Base Mainnet as published by each provider: | Service | What it does | Billing | |---|---|---| @@ -51,7 +51,7 @@ The first live services cover token creation plus DeFi market data and on-chain | DIA | Decentralized, multi-source oracle prices by symbol or by chain + contract address | $0.000001 / call | | GoPlus | Token and address security checks — honeypot/scam screening, malicious-address and risky-approval detection | $0.000001 / call | -All of the above are in the **Finance** category and available on both TRON and BNB Chain. +All of the above are in the **Finance** category. Check each endpoint's `x402Routes` for its currently published TRON, BNB Chain, and Base Mainnet routes. :::note The live service list and statistics (service count, chain count, etc.) are **generated dynamically** from catalog data — treat `/api/catalog.json` as the source of truth; this page hard-codes no numbers, and the catalog grows as new services are listed. diff --git a/docs/x402/api-catalog/list-your-service.md b/docs/x402/api-catalog/list-your-service.md index 31f593fb..318e708d 100644 --- a/docs/x402/api-catalog/list-your-service.md +++ b/docs/x402/api-catalog/list-your-service.md @@ -8,7 +8,7 @@ description: List your API in the API Catalog — apply via the form or open a P List once — every AI Agent call after that is revenue in. -Put your API behind the Gateway and it appears in the catalog: any Agent can discover it, call it, and pay for it. Payments settle to the wallet you specify in real time — **no platform escrow, no payout cycle**; settle on TRON or BNB Chain; your existing API stays exactly as it is, **not one line of code changes**, and you set the prices. +Put your API behind the Gateway and it appears in the catalog: any Agent can discover it, call it, and pay for it. Payments settle to the wallet you specify in real time — **no platform escrow, no payout cycle**; settle on TRON, BNB Chain, or Base Mainnet; your existing API stays exactly as it is, **not one line of code changes**, and you set the prices. ## The big picture: what listing actually means @@ -233,7 +233,7 @@ CI enforces the following rules — go through them before submitting: - `version` must be `1`. - `fqn` is lowercase letters/digits/hyphens and must match the directory name. - `category` must be one of the allowed values (see [reference](./reference.md#allowed-categories)). -- `chains` needs at least one entry, using CAIP-2 style chain IDs — mainnets or testnets (e.g. `tron:0x2b6653dc`, `tron:0xcd8690dc`, `eip155:56`, `eip155:97`). +- `chains` needs at least one entry, using CAIP-2 style chain IDs. The public catalog publishes mainnet routes such as `tron:0x2b6653dc`, `eip155:56`, and Base Mainnet `eip155:8453`. - `isFirstParty`, `isFeatured` (booleans) and `featuredTags` (string array, may be empty `[]`) are **required** — missing any of them fails validation. - For every endpoint: `method` must be uppercase, `path` must start with `/`, and `maxPriceUsd` must not be less than `minPriceUsd`. - _(Optional)_ An endpoint that settles across multiple chains can add `x402Routes` — one entry per network (`network`, `provider`, `scheme`, `url`). See the [reference](./reference.md#x402routes--multi-network-routing). diff --git a/docs/x402/api-catalog/reference.md b/docs/x402/api-catalog/reference.md index 08ae5dd7..8b33231e 100644 --- a/docs/x402/api-catalog/reference.md +++ b/docs/x402/api-catalog/reference.md @@ -60,14 +60,19 @@ An endpoint may serve the same capability across several chains, each settling t | Field | Type | Description | |---|---|---| -| `network` | string | CAIP-2 chain ID this route settles on (e.g. `tron:0x2b6653dc`, `eip155:56`) | +| `network` | string | Canonical CAIP-2 chain ID this route settles on (e.g. `tron:0x2b6653dc`, `eip155:56`, `eip155:8453`). Legacy TRON aliases such as `tron:nile` are rejected by schema validation. | | `provider` | string | The gateway provider `fqn` that handles this network | -| `scheme` | string | x402 payment scheme for this route, e.g. `exact` — each route declares its own | +| `scheme` | string | x402 payment scheme for this route: `exact` or, on TRON, `exact_gasfree` — each route declares its own | +| `assetTransferMethod` | string | Authorization used by an `exact` route: `permit2` on TRON and BSC, `eip3009` on Base USDC. **Omit** it on `exact_gasfree` routes. | | `url` | string | Full gateway URL for this network's route | The build passes this through to outputs as `x402_routes`. When present, callers/agents pick the route matching their intended payment chain; the top-level `url` remains the default route. -For example, a token-launch endpoint might expose one route per supported chain — TRON Mainnet and BSC Mainnet — each with its own `provider` and `scheme`. To call one, point `x402-cli pay` at the chosen route's `url` and pass the matching `--network` / `--scheme`: +:::note GasFree routes +On TRON you can add an `exact_gasfree` route alongside the `exact` one for the same endpoint: a relayer pays the network energy and deducts its fee from the payment token, so the payer needs no TRX. GasFree routes are TRON-only and must not carry `assetTransferMethod`. With x402 SDK 1.0.1 the relayer cost is estimated client-side, so catalog routes must **not** publish the legacy `fee` or `feeConfig` fields. +::: + +For example, an endpoint may expose one route per supported chain — TRON Mainnet, BSC Mainnet, and Base Mainnet — each with its own `provider` and `scheme`. To call one, point `x402-cli pay` at the chosen route's `url` and pass the matching `--network` / `--scheme`: ```bash x402-cli pay 'https://x402-gateway.bankofai.io/providers//' \ @@ -116,6 +121,7 @@ security shopping storage translation | TRON Shasta testnet | `tron:0x94a9059e` | | BNB Chain (BSC) | `eip155:56` | | BNB Smart Chain testnet | `eip155:97` | +| Base mainnet | `eip155:8453` | The build resolves each chain ID into display metadata (`kind` / `label` / `label_zh`) so the frontend doesn't have to parse CAIP-2 itself — see [Frontend display fields](#frontend-display-fields). @@ -185,7 +191,7 @@ To save the frontend from parsing raw IDs and picking translations, the build al | `sub_title` | Secondary display line (from `subTitle`, falls back to `subtitle`) | | `sub_title_zh` | Chinese secondary display line (from `i18n.zh-CN.subtitle` / `subTitle`, falls back to `subtitle`) | | `category_meta` | `{ id, label, label_zh }` for the category | -| `chain_kinds` | De-duplicated friendly chain kinds, e.g. `["tron"]`, `["bnb"]` | +| `chain_kinds` | De-duplicated friendly chain kinds, e.g. `["tron"]`, `["bnb"]`, `["base"]` | | `chains_meta` | Per-chain `{ id, kind, label, label_zh }`, so the frontend never parses CAIP-2 | These are additive — the raw `title`, `subtitle`, `category`, `chains`, and `i18n.zh-CN` are still present. diff --git a/docs/x402/cli/command-reference.md b/docs/x402/cli/command-reference.md index 81b9fd0c..8417edbf 100644 --- a/docs/x402/cli/command-reference.md +++ b/docs/x402/cli/command-reference.md @@ -46,18 +46,35 @@ x402-cli pay [options] | `--method ` | HTTP method (default: `GET`) | | `--header "Name: Value"` | Request header; repeatable | | `--body ` | Request body for non-`GET`/`HEAD` methods | -| `--network ` | Require a specific network (e.g. `tron:nile`) | -| `--token ` | Require a specific token (e.g. `USDT`) | -| `--scheme ` | Require a specific x402 scheme (e.g. `exact`) | +| `--network ` | Require a specific network (e.g. `tron:0xcd8690dc`, `base-mainnet`) | +| `--token ` | Require a specific token (e.g. `USDT`, `USDC`) | +| `--asset
` | Require a specific asset address | +| `--decimals ` | Decimals for an unregistered explicit asset | +| `--scheme ` | Require a specific x402 scheme: `exact` or `exact_gasfree` | +| `--gasfree-api-url ` | Override the TRON GasFree relayer API URL (env `X402_GASFREE_API_URL`) | +| `--max-gasfree-fee ` | Maximum GasFree relayer fee, in token units | +| `--max-gasfree-fee-raw ` | Maximum GasFree relayer fee, in smallest units | | `--max-amount ` | Maximum human-readable amount you'll pay | | `--max-raw-amount ` | Maximum amount in smallest units | | `--dry-run` | Read the requirement but do not sign or pay | -| `--private-key ` | Explicit payer key (or use the env vars below) | +| `--wallet-id ` | Explicitly select a configured Agent Wallet (env `AGENT_WALLET_ID`) | +| `--private-key ` | Override Agent Wallet — development and CI only | | `--rpc-url ` | Explicit network RPC URL | | `--timeout-ms ` | Network timeout in ms (default: `30000`) | | `--json` | Print the JSON envelope | -The payer key is read from `--private-key`, or from an environment variable: `TRON_PRIVATE_KEY` for TRON networks and `EVM_PRIVATE_KEY` for EVM networks, with `PRIVATE_KEY` accepted as a fallback for either network. +Registered token decimals are authoritative and can't be overridden with `--decimals`. Pass `--asset` and `--decimals` together only for an unregistered, non-Base asset. + +### Paying with Agent Wallet {#paying-with-agent-wallet} + +By default `pay` resolves the **active [Agent Wallet](../../Agent-Wallet/Intro.md)** for the selected network and delegates signing to it — no private key in a config file or environment variable. + +- If wallets are configured but none is active, the CLI **stops before signing** rather than silently picking the first one. Set an active wallet, or select one explicitly with `--wallet-id` / `AGENT_WALLET_ID`. +- Use `AGENT_WALLET_DIR` to point at a non-default Agent Wallet directory. +- The CLI never reads private keys out of `wallets_config.json`. +- On EVM networks it checks the payer's token balance before signing, and returns the resolved wallet ID, address, and raw balance in the result. The EIP-712 payer must match that address. + +For **development and CI only**, `--private-key` or the `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` environment variables override Agent Wallet. Prefer the environment variables over the flag in shared environments — command-line arguments can be visible to other local processes. **Examples:** @@ -68,8 +85,8 @@ x402-cli pay https://api.example.com/paid --dry-run --json ```bash # Pay, but never spend more than 0.01 USDT -TRON_PRIVATE_KEY= x402-cli pay https://api.example.com/paid \ - --network tron:nile --token USDT --max-amount 0.01 +x402-cli pay https://api.example.com/paid \ + --network tron:0xcd8690dc --token USDT --max-amount 0.01 ``` ```bash @@ -80,6 +97,59 @@ x402-cli pay https://api.example.com/paid \ If the endpoint does not return `402`, the CLI reports the actual status and response instead of paying. +### GasFree payments (TRON) {#gasfree-payments-tron} + +On TRON, `scheme=exact_gasfree` lets a relayer pay the network energy and deduct its fee from the payment token, so the payer doesn't need to hold TRX. The CLI normally selects this scheme automatically when the server's `402` challenge advertises it; pass `--scheme exact_gasfree` to require it explicitly. + +GasFree fees are **separate** from the advertised payment amount. Set a fee limit so the CLI estimates the relayer fee and rejects the payment before signing if the estimate is too high: + +```bash +x402-cli pay https://api.example.com/pay \ + --network tron:0xcd8690dc --token USDT \ + --scheme exact_gasfree \ + --max-amount 0.01 \ + --max-gasfree-fee 0.5 \ + --json +``` + +`--max-gasfree-fee` and `--max-gasfree-fee-raw` are mutually exclusive, and only apply to an `exact_gasfree` requirement. Override the relayer endpoint with `--gasfree-api-url ` or `X402_GASFREE_API_URL`. + +A paid response distinguishes `settled` (the payment cleared on-chain) from `delivered` (the upstream HTTP business response succeeded). A settled upstream failure reports `paid=true`, `settled=true`, `delivered=false` and still includes its transaction information — inspect the transaction and provider behavior before retrying. + +### Paying on Base {#paying-on-base} + +Base settles USDC through the standard `exact` EVM flow, using **EIP-3009** (`transferWithAuthorization`) rather than Permit2. You don't select that — the CLI applies the right authorization for the network. + +```bash +x402-cli pay https://api.example.com/pay \ + --network base-mainnet \ + --token USDC \ + --max-amount 0.01 \ + --rpc-url +``` + +The built-in public RPC is meant for development only. In production, supply an RPC endpoint via `--rpc-url`, `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532`, or `EVM_RPC_URL`. + +:::caution Redirects are not followed +The probe and the signed retry deliberately do **not** follow HTTP redirects, so `PAYMENT-SIGNATURE` is never forwarded to another origin. If an endpoint redirects, inspect the destination and call the final trusted URL explicitly. +::: + +### Environment variables {#pay-environment-variables} + +Some settings have no flag and are configured through the environment only: + +| Variable | Purpose | +| :--- | :--- | +| `AGENT_WALLET_DIR` | Use a non-default Agent Wallet directory | +| `AGENT_WALLET_ID` | Select a configured wallet (same as `--wallet-id`) | +| `TRON_RPC_URL` | TRON RPC endpoint (falls back from `--rpc-url`) | +| `TRON_GRID_API_KEY` | TronGrid API key — set this to avoid public rate limits | +| `X402_TRON_ALLOWANCE_MODE` | TRON allowance handling; defaults to `auto` | +| `EVM_RPC_URL` | Default EVM RPC endpoint | +| `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` | Per-network RPC for Base Mainnet / Base Sepolia | +| `X402_GASFREE_API_URL` | Override the TRON GasFree relayer API | +| `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` | Override Agent Wallet — development and CI only | + --- ## `serve` @@ -95,7 +165,8 @@ x402-cli serve --pay-to
[options] | `--pay-to
` | **(required)** Recipient wallet address | | `--amount ` | Human-readable token amount (default: `0.0001`) | | `--raw-amount ` | Amount in smallest units (mutually exclusive with `--amount`) | -| `--network ` | Payment network (default: `tron:nile`) | +| `--network ` | Payment network (default: `tron:0xcd8690dc`) | +| `--scheme ` | Payment scheme: `exact` or `exact_gasfree` (default: `exact`) | | `--token ` | Token symbol (default: `USDT`) | | `--asset
` | Explicit token address for an unregistered token | | `--decimals ` | Token decimals, required with an unregistered `--asset` | @@ -103,6 +174,7 @@ x402-cli serve --pay-to
[options] | `--port ` | Bind port (default: `4020`) | | `--resource-url ` | URL advertised in the payment requirement | | `--facilitator-url ` | Facilitator base URL (default: `https://facilitator.bankofai.io`) | +| `--valid-for-seconds ` | How long the payment requirement stays valid (default: `300`) | | `--timeout-ms ` | Facilitator timeout in ms (default: `30000`) | | `-d, --daemon` | Run in the background and print the child pid | | `--json` | Print the JSON envelope | @@ -119,7 +191,7 @@ The server exposes four routes: **Examples:** ```bash -x402-cli serve --pay-to T... --network tron:nile --token USDT +x402-cli serve --pay-to T... --network tron:0xcd8690dc --token USDT ``` ```bash @@ -139,10 +211,12 @@ x402-cli roundtrip --pay-to
[serve/pay options] **Example:** ```bash -TRON_PRIVATE_KEY= x402-cli roundtrip \ - --pay-to T... --amount 0.0001 --network tron:nile --token USDT +x402-cli roundtrip \ + --pay-to T... --amount 0.0001 --network tron:0xcd8690dc --token USDT ``` +With `--json`, `roundtrip` emits a single JSON document containing separate `serve` and `pay` results. + --- ## `gateway` diff --git a/docs/x402/cli/faq.md b/docs/x402/cli/faq.md index e07ebc4c..0630ff5b 100644 --- a/docs/x402/cli/faq.md +++ b/docs/x402/cli/faq.md @@ -34,20 +34,23 @@ Yes. From a project that has it installed, run `node dist/cli.js `, or ### Do I need a wallet to use the CLI? -Only for actual payments. Read-only commands — `pay --dry-run`, `catalog search`, `catalog show`, `gateway check` — need no wallet. A real `pay` or `roundtrip` requires a payer private key. +Only for actual payments. Read-only commands — `pay --dry-run`, `catalog search`, `catalog show`, `gateway check` — need no wallet. A real `pay` or `roundtrip` signs with your active [Agent Wallet](../../Agent-Wallet/Intro.md). -### How do I provide my private key? +### How does the CLI choose which wallet to sign with? -Set one of these environment variables: +It resolves the **active Agent Wallet** for the payment network. If wallets are configured but none is marked active, the CLI stops before signing instead of guessing — set one active, or select one explicitly: -- **TRON networks** → `TRON_PRIVATE_KEY` -- **EVM networks** (BSC) → `EVM_PRIVATE_KEY` -- **Either network** → `PRIVATE_KEY`, used as a fallback when the network-specific variable isn't set +- `--wallet-id ` or `AGENT_WALLET_ID` — pick a specific configured wallet +- `AGENT_WALLET_DIR` — use a non-default Agent Wallet directory -You can also pass `--private-key ` for a single command, but avoid this in shared shells or committed scripts — command-line arguments are recorded in shell history and process listings. +The CLI never reads private keys out of `wallets_config.json`. On EVM networks it also checks the payer's token balance before signing, and returns the resolved wallet ID, address, and raw balance in the result. + +### Can I still use a raw private key? + +Yes, but only for development and CI: `--private-key `, or the `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` environment variables. Prefer the environment variable over the flag in shared environments — command-line arguments are recorded in shell history and process listings. :::caution -For anything beyond throwaway testing, use an [agent-wallet](../../Agent-Wallet/Intro.md) payer wallet rather than raw environment keys, and keep only the minimum funds the current task needs in the payer address. +For anything beyond throwaway testing, use Agent Wallet rather than raw keys, and keep only the minimum funds the current task needs in the payer address. ::: ### Will a payment ever spend more than I expect? @@ -56,7 +59,17 @@ Not if you cap it. Use `--max-amount ` or `--max-raw-amount ` with `--decimals `. +TRON (`tron:0x2b6653dc`, `tron:0xcd8690dc`, `tron:0x94a9059e`), BSC (`eip155:56`, `eip155:97`), and Base (`eip155:8453`, `eip155:84532`), with a built-in registry for USDT, USDD, and USDC depending on the network. See [x402 CLI overview](./index.md#supported-networks--tokens) for the full table. Registered token decimals are authoritative; pass `--asset
` with `--decimals ` only for an unregistered, non-Base asset. + +Pass TRON networks as their canonical CAIP-2 identifiers (`tron:0x…`). Legacy identifiers such as `tron:nile`, `tron:mainnet`, or `mainnet` are no longer accepted — the CLI rejects them and tells you the canonical identifier to use. EVM aliases (`bsc-mainnet`, `bsc-testnet`, `base-mainnet`, `base-sepolia`) are accepted. + +### How is paying on Base different? + +Base settles USDC with **EIP-3009** (`transferWithAuthorization`) instead of Permit2, still under the `exact` scheme. You don't configure this — the CLI applies the right authorization per network. The one thing to set yourself is RPC: the built-in public endpoint is for development only, so in production pass `--rpc-url`, or set `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` / `EVM_RPC_URL`. See [Paying on Base](./command-reference.md#paying-on-base). + +### Can I pay without holding TRX? + +Yes, on TRON, using GasFree. With `scheme=exact_gasfree`, a relayer pays the network energy and deducts its fee from the payment token, so the payer wallet needs only the stablecoin — no TRX. The CLI selects `exact_gasfree` automatically when the endpoint advertises it, or you can require it with `--scheme exact_gasfree`. Because the relayer fee is separate from the payment amount, cap it with `--max-gasfree-fee `. See [GasFree payments](./command-reference.md#gasfree-payments-tron). --- @@ -66,7 +79,16 @@ Every failure prints a stable error `code`, a message, and a `hint`. Add `--json | Code | What happened | How to fix it | | :--- | :--- | :--- | -| `WALLET_NOT_CONFIGURED` | No payer key found | Set `TRON_PRIVATE_KEY` / `EVM_PRIVATE_KEY` / `PRIVATE_KEY`, or configure an agent-wallet payer | +| `WALLET_NOT_CONFIGURED` | No active Agent Wallet for this network | Set an active wallet, or select one with `--wallet-id` / `AGENT_WALLET_ID`. For dev/CI, use `--private-key` or a `*_PRIVATE_KEY` variable | +| `WALLET_PASSWORD_REQUIRED` | Agent Wallet needs its unlock password | Provide the password through Agent Wallet's supported secure configuration | +| `WALLET_DECRYPTION_FAILED` | Wrong password for the Agent Wallet | Unlock with the correct password and retry | +| `WALLET_CONFIG_CORRUPT` | Agent Wallet configuration is unreadable | Check `~/.agent-wallet/wallets_config.json`, or recreate the local configuration | +| `WALLET_NETWORK_ERROR` | Can't reach the Agent Wallet backend | Check connectivity to the configured wallet backend | +| `WALLET_SIGNING_FAILED` | The wallet couldn't produce the signature | Confirm the active wallet supports this network and typed-data request | +| `WALLET_UNSUPPORTED_OPERATION` | The wallet backend can't sign typed data for this network | Switch to a wallet backend that supports typed-data signing here | +| `WALLET_AUTH_FAILED` | Remote wallet authentication was rejected | Check the remote wallet's authentication configuration | +| `WALLET_ERROR` | Other Agent Wallet failure | Inspect the active wallet configuration and backend status | +| `TOKEN_TRANSFER_FAILED` | The token `transferFrom` reverted | Check token balance, the token contract, and the payer's allowance | | `TRON_ACCOUNT_NOT_ACTIVATED` | The TRON address has never been used on-chain | Send it a small amount of TRX to activate it before signing | | `INSUFFICIENT_TOKEN_BALANCE` | Payer lacks the token being charged | Fund the payer with the exact token and network the provider advertises | | `INSUFFICIENT_GAS` | Not enough native gas / energy | Fund the payer with the network's native gas token (TRX / BNB) | diff --git a/docs/x402/cli/index.md b/docs/x402/cli/index.md index b27a2607..5cd5c6e2 100644 --- a/docs/x402/cli/index.md +++ b/docs/x402/cli/index.md @@ -14,10 +14,12 @@ Think of it this way: the [x402 SDK](../sdk-features.md) is what you embed insid ```bash # Pay any x402-protected endpoint -x402-cli pay https://api.example.com/paid --network tron:nile --token USDT +x402-cli pay https://api.example.com/paid --network tron:0xcd8690dc --token USDT ``` -It is built entirely on the published TypeScript SDK packages — `@bankofai/x402-core`, `@bankofai/x402-evm`, and `@bankofai/x402-tron` — and every stablecoin payment uses `scheme=exact` with Permit2 authorization (`extra.assetTransferMethod=permit2`). +It is built entirely on the published TypeScript SDK packages — `@bankofai/x402-core`, `@bankofai/x402-evm`, `@bankofai/x402-fetch`, and `@bankofai/x402-tron`. Stablecoin payments use `scheme=exact`: Permit2 authorization on TRON and BSC, EIP-3009 on Base USDC. TRON also supports `scheme=exact_gasfree`, where a relayer pays the network energy and deducts its fee from the payment token — so the payer doesn't need to hold TRX. See [GasFree payments](./command-reference.md#gasfree-payments-tron). + +By default, `pay` signs with your active [Agent Wallet](../../Agent-Wallet/Intro.md) — no private key in an environment variable. See [Paying with Agent Wallet](./command-reference.md#paying-with-agent-wallet). --- @@ -27,13 +29,13 @@ The CLI groups its capabilities into five commands. | Command | What it does | Example | | :--- | :--- | :--- | -| **`pay`** | Pay an x402-protected URL. Probes the endpoint, reads the `402` challenge, signs a payment, and retries. | `x402-cli pay --network tron:nile --token USDT` | +| **`pay`** | Pay an x402-protected URL. Probes the endpoint, reads the `402` challenge, signs a payment, and retries. | `x402-cli pay --network tron:0xcd8690dc --token USDT` | | **`serve`** | Run a local x402 paywall that returns `402 Payment Required` and settles through a facilitator. | `x402-cli serve --pay-to
--amount 0.0001` | | **`roundtrip`** | Start a temporary server, immediately pay it, then exit — the fastest way to smoke-test end to end. | `x402-cli roundtrip --pay-to
` | | **`gateway`** | Manage local gateway provider files: validate, scaffold, start, and build catalog assets. | `x402-cli gateway check ./providers` | | **`catalog`** | Search, cache, inspect, and export the hosted provider catalog. | `x402-cli catalog search "weather"` | -Read-only commands (`pay --dry-run`, `catalog search`, `gateway check`) need no wallet. Only an actual payment requires a payer private key. +Read-only commands (`pay --dry-run`, `catalog search`, `gateway check`) need no wallet. An actual payment requires a configured signing wallet; raw private keys are only a development/CI override. --- @@ -42,17 +44,34 @@ Read-only commands (`pay --dry-run`, `catalog search`, `gateway check`) need no Output is human-friendly text by default. Add `--json` to any command for a stable, machine-readable envelope — ideal for scripts and AI agents: ```bash -x402-cli pay https://api.example.com/paid --dry-run --json +x402-cli pay 'https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols' \ + --network tron:0x2b6653dc \ + --token USDT \ + --dry-run \ + --json ``` ```json { "ok": true, - "command": "client", - "network": "tron:nile", + "command": "pay", + "component": "client", + "network": "tron:0x2b6653dc", "scheme": "exact", "result": { - "url": "https://api.example.com/paid", + "url": "https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols", + "resource": "https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols", + "selected": { + "scheme": "exact", + "network": "tron:0x2b6653dc", + "amount": "1", + "asset": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", + "payTo": "TLXPgJVJFgL97gc49j8w8kC22mDTpH9EGa", + "maxTimeoutSeconds": 300, + "extra": { + "assetTransferMethod": "permit2" + } + }, "message": "Dry run - no payment submitted" } } @@ -68,23 +87,28 @@ The CLI ships a built-in token registry. Pass a network with `--network` and a t | Network | Identifier | Built-in tokens | | :--- | :--- | :--- | -| **TRON Mainnet** | `tron:mainnet` | USDT, USDD | -| **TRON Nile Testnet** | `tron:nile` | USDT, USDD | -| **TRON Shasta Testnet** | `tron:shasta` | USDT | +| **TRON Mainnet** | `tron:0x2b6653dc` | USDT, USDD | +| **TRON Nile Testnet** | `tron:0xcd8690dc` | USDT, USDD | +| **TRON Shasta Testnet** | `tron:0x94a9059e` | USDT | | **BSC Mainnet** | `eip155:56` | USDT | | **BSC Testnet** | `eip155:97` | USDT, USDC | +| **Base Mainnet** | `eip155:8453` | USDC | +| **Base Sepolia Testnet** | `eip155:84532` | USDC | -Convenience aliases are accepted and normalized automatically: +Always pass TRON networks as their canonical CAIP-2 identifiers (`tron:0x…`). Legacy aliases like `tron-mainnet`, `tron:nile`, or `mainnet` are **rejected** — the CLI reports the canonical identifier to use instead. Only the EVM aliases are still accepted and normalized automatically: | Alias | Canonical identifier | | :--- | :--- | -| `tron-mainnet` | `tron:mainnet` | -| `tron-nile` | `tron:nile` | -| `tron-shasta` | `tron:shasta` | | `bsc-mainnet` | `eip155:56` | | `bsc-testnet` | `eip155:97` | +| `base-mainnet` | `eip155:8453` | +| `base-sepolia` | `eip155:84532` | + +Registered token decimals are authoritative and can't be overridden. For an unregistered, non-Base asset, pass `--asset
` together with `--decimals `. -For a token that isn't in the registry, pass `--asset
` together with `--decimals `. +:::note Authorization differs by chain +TRON and BSC stablecoin payments use **Permit2** authorization; Base USDC uses **EIP-3009** (`transferWithAuthorization`). Both run through the same `exact` scheme — the CLI picks the right one for the network, so you don't configure it yourself. +::: --- @@ -110,10 +134,11 @@ Use the CLI to explore, test, and script against x402 endpoints, or to give an A :::warning Payments move real on-chain assets and cannot be reversed. Keep these principles in mind: -- **Never hardcode private keys.** Prefer environment variables (`TRON_PRIVATE_KEY`, `EVM_PRIVATE_KEY`, `PRIVATE_KEY`) or an [agent-wallet](../../Agent-Wallet/Intro.md) payer wallet over the `--private-key` flag in shared environments. -- **Test on testnet first.** Use `tron:nile` or `eip155:97` before running any payment on mainnet. +- **Let Agent Wallet hold the key.** It is the default payer and delegates signing to the configured wallet backend, which may be local or remote. You never need to put a private key in the CLI configuration or environment. `--private-key` and the `*_PRIVATE_KEY` variables exist for development and CI only. +- **Test on testnet first.** Use `tron:0xcd8690dc`, `eip155:97`, or `eip155:84532` before running any payment on mainnet. - **Preview before you pay.** Run `pay --dry-run` to inspect the exact requirement before signing. - **Cap the amount.** Use `--max-amount` or `--max-raw-amount` so a mispriced endpoint can't overcharge you. +- **Don't follow redirects blindly.** The CLI deliberately won't auto-follow an HTTP redirect on a paid request, so `PAYMENT-SIGNATURE` is never forwarded to another origin. If an endpoint redirects, verify the destination and call the final URL explicitly. - **Fund the minimum.** Only keep the funds the current task needs in the payer address. ::: diff --git a/docs/x402/cli/quickstart.md b/docs/x402/cli/quickstart.md index 383ca04c..e478a828 100644 --- a/docs/x402/cli/quickstart.md +++ b/docs/x402/cli/quickstart.md @@ -16,7 +16,8 @@ Before you start, make sure you have: 1. **Node.js** >= 20 ([download](https://nodejs.org/)) 2. **npm** (comes with Node.js) -3. A funded testnet address for the payment step — a TRON **Nile** address holding a small amount of test **USDT** and **TRX** (for energy). See [Wallet](../core-concepts/wallet.md). +3. An **[Agent Wallet](../../Agent-Wallet/QuickStart.md)** with an active wallet for the network you'll pay on — this is how the CLI signs by default +4. A funded testnet address for the payment step — a TRON **Nile** address holding a small amount of test **USDT** and **TRX** (for energy). See [Wallet](../core-concepts/wallet.md). Verify your environment: @@ -48,54 +49,56 @@ You should see the version number and the list of commands (`pay`, `serve`, `rou ## Step 2: Try it without spending anything -The fastest way to see a real `402` challenge is a **dry run**. This probes an endpoint, reads its payment requirement, and prints exactly what you'd be asked to pay — without signing or spending: +The fastest way to see a real `402` challenge is a **dry run**. This probes a live TRON Mainnet endpoint, reads its payment requirement, and prints exactly what you'd be asked to pay — without signing or spending: ```bash -x402-cli pay https://api.example.com/paid \ - --network tron:nile \ +x402-cli pay 'https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols' \ + --network tron:0x2b6653dc \ --token USDT \ --dry-run \ --json ``` -The `--dry-run` output includes the selected requirement (network, asset, amount, recipient). This is your safety net: always dry-run an unfamiliar endpoint before paying it. +This step reads a TRON Mainnet requirement, but `--dry-run` never signs or submits a payment. Its output includes the selected requirement (network, asset, amount, recipient). This is your safety net: always dry-run an unfamiliar endpoint before paying it. --- ## Step 3: Run a full roundtrip on testnet -`roundtrip` starts a temporary local paywall, pays it, and exits — a complete end-to-end test of your setup. You'll need a payer private key for the Nile testnet. +`roundtrip` starts a temporary local paywall, pays it, and exits — a complete end-to-end test of your setup. Your active Agent Wallet for Nile does the signing. ```bash -TRON_PRIVATE_KEY= \ x402-cli roundtrip \ --pay-to \ --amount 0.0001 \ - --network tron:nile \ + --network tron:0xcd8690dc \ --token USDT ``` When it succeeds, the CLI prints the settled transaction. That transaction hash is your proof the payment cleared on-chain — congratulations, your setup works end to end. :::caution Keep your keys safe -Pass private keys through environment variables (`TRON_PRIVATE_KEY` for TRON, `EVM_PRIVATE_KEY` for EVM, or `PRIVATE_KEY` as a fallback for either), never as plain command-line flags in shared shells or scripts committed to source control — command-line arguments may be visible to other local processes. For anything beyond throwaway testing, use an [agent-wallet](../../Agent-Wallet/QuickStart.md) payer wallet. +The CLI signs with your active [Agent Wallet](../../Agent-Wallet/QuickStart.md), so no private key goes into a shell or a config file. If wallets are configured but none is active, the CLI stops before signing — set one active, or pick one with `--wallet-id`. The `--private-key` flag and `*_PRIVATE_KEY` variables exist for development and CI only; prefer the environment variable over the flag, since command-line arguments can be visible to other local processes. ::: --- ## Step 4: Pay a real x402 endpoint -Once the roundtrip works, paying any x402-protected URL is the same `pay` command pointed at a real resource: +Once the roundtrip works, paying any x402-protected URL uses the same command. Replace the placeholders below with the URL, network, and token advertised by the provider: ```bash -TRON_PRIVATE_KEY= \ -x402-cli pay https://api.example.com/paid \ - --network tron:nile \ - --token USDT \ +x402-cli pay '' \ + --network \ + --token \ --max-amount 0.01 ``` -`--max-amount` caps what you're willing to pay: if the endpoint's price exceeds it, the CLI aborts before signing. For EVM networks, use `EVM_PRIVATE_KEY` (or the `PRIVATE_KEY` fallback) and an EVM network such as `eip155:97`. +`--max-amount` caps what you're willing to pay: if the endpoint's price exceeds it, the CLI aborts before signing. The same command works on EVM networks — just point `--network` at one, such as `eip155:97` (BSC Testnet) or `base-sepolia` (Base Sepolia, USDC). + +:::tip No TRX? Use GasFree +On TRON, if the endpoint advertises `exact_gasfree`, the CLI can pay without any TRX in your wallet — a relayer covers the network energy and takes its fee from the payment token. The CLI selects it automatically, or you can require it with `--scheme exact_gasfree` and cap the relayer fee with `--max-gasfree-fee`. See [GasFree payments](./command-reference.md#gasfree-payments-tron). +::: --- @@ -107,7 +110,7 @@ Want to charge for a resource instead of paying for one? Start a local x402 serv x402-cli serve \ --pay-to \ --amount 0.0001 \ - --network tron:nile \ + --network tron:0xcd8690dc \ --token USDT \ --port 4020 ``` @@ -122,7 +125,7 @@ It exposes: In another terminal, pay it: ```bash -TRON_PRIVATE_KEY= x402-cli pay http://127.0.0.1:4020/pay --network tron:nile --token USDT +x402-cli pay http://127.0.0.1:4020/pay --network tron:0xcd8690dc --token USDT ``` Point the server at a specific facilitator with `--facilitator-url` (defaults to `https://facilitator.bankofai.io`), and add `--daemon` to run it in the background and print the child process id. diff --git a/docs/x402/core-concepts/gateway.md b/docs/x402/core-concepts/gateway.md index c282f71c..f3e6eb3f 100644 --- a/docs/x402/core-concepts/gateway.md +++ b/docs/x402/core-concepts/gateway.md @@ -62,7 +62,7 @@ Providers turn calls into cash flow. Agents turn calls into capabilities. The ga ### For API providers: list your API, earn on every call - **Straight to your wallet** — payments settle to your payout wallet in real time; no platform escrow, no payout cycle. -- **Native multi-chain** — settle on TRON or BNB Chain, the provider's choice. +- **Native multi-chain** — settle on TRON, BNB Chain, or Base Mainnet, according to the provider's published route. - **Zero-touch onboarding** — your existing API stays exactly as it is, not one line changes. - **You set the price** — flexible per-endpoint, per-tier pricing; free routes stay free. diff --git a/docs/x402/core-concepts/network-and-token-support.md b/docs/x402/core-concepts/network-and-token-support.md index 298c1dad..8f3c236b 100644 --- a/docs/x402/core-concepts/network-and-token-support.md +++ b/docs/x402/core-concepts/network-and-token-support.md @@ -31,6 +31,19 @@ In the x402 protocol (on-the-wire), BSC uses the EIP-155 chain ID format: --- +## Base Network Identifiers + +Base uses canonical EIP-155 identifiers on the x402 wire: + +| Network Name | Protocol ID | Description | +| :----------- | :---------- | :---------- | +| **Base Mainnet** | `eip155:8453` | Production network; published by the API Catalog | +| **Base Sepolia** | `eip155:84532` | CLI/SDK test network | + +Base Mainnet uses official USDC and the `exact` scheme with EIP-3009 authorization. The payer signs a `transferWithAuthorization` message off-chain; no Permit2 approval is required. + +--- + ## Overview x402 is purpose-built for blockchain ecosystems, enabling native on-chain payment verification and settlement. @@ -45,13 +58,14 @@ The protocol uses secure signing mechanisms to ensure tamper-resistant message a | **TRON Shasta** | **Testnet** | Long-running alternative testnet | | **BSC Mainnet** | **Mainnet** | **Production network** for real-value assets | | **BSC Testnet** | **Testnet** | **Recommended testnet** for BSC development | +| **Base Mainnet** | **Mainnet** | **Production network** using official USDC | +| **Base Sepolia** | **Testnet** | CLI/SDK testing; not published in the API Catalog | --- ## Supported Tokens -x402 fully supports **TRC-20 and BEP-20** standard tokens. -By default, **USDT** and **USDD** are used as primary settlement currencies. +x402 supports **TRC-20, BEP-20, and ERC-20** tokens. TRON/BSC routes use their configured stablecoins; Base uses official USDC. ### Supported Token List @@ -67,10 +81,12 @@ By default, **USDT** and **USDD** are used as primary settlement currencies. | **USDT** | `eip155:97` | `0x337610d27c682E347C9cD60BD4b3b107C9d34dDd` | | **USDC** | `eip155:97` | `0x64544969ed7EBf5f083679233325356EbE738930` | | **DHLU** | `eip155:97` | `0x375cADdd2cB68cE82e3D9B075D551067a7b4B816` | +| **USDC** | `eip155:8453` | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | +| **USDC** | `eip155:84532` | `0x036CbD53842c5426634e7929541eC2318f3dCF7e` | > **Extensibility**: The protocol is highly extensible. By registering tokens in the `TokenRegistry`, you can easily support any custom TRC-20 or BEP-20 token. -> **Token selection for the `exact` scheme**: ERC-3009 tokens (e.g. BSC testnet **DHLU**) settle gaslessly via `transferWithAuthorization`. Plain ERC-20 tokens (e.g. BSC USDC/USDT, TRON USDT/USDD) settle via the Permit2 path — the client auto-broadcasts a one-time `approve(Permit2)` on first payment. The per-token method is data in the server's `accepts[].price.extra`: ERC-3009 → `{ name, version }`; plain ERC-20 → `{ assetTransferMethod: "permit2" }`. +> **Token selection for the `exact` scheme**: EIP-3009 tokens (for example official Base USDC and BSC testnet DHLU) settle gaslessly via `transferWithAuthorization`. Plain ERC-20 tokens (for example BSC USDC/USDT and TRON USDT/USDD) settle via the Permit2 path — the client auto-broadcasts a one-time `approve(Permit2)` on first payment. The per-token method is data in the server's `accepts[].price.extra`: EIP-3009 → `{ name, version }`; plain ERC-20 → `{ assetTransferMethod: "permit2" }`. --- @@ -95,8 +111,8 @@ x402 uses typed data signing for all payment-related signatures. When configuring an `HTTP 402` payment request on the server side, you must explicitly define: -1. **Network** – The unique network identifier (e.g., `tron:0xcd8690dc`) -2. **Asset** – The TRC-20/BEP-20 token **contract address** +1. **Network** – The unique network identifier (e.g., `tron:0xcd8690dc` or `eip155:8453`) +2. **Asset** – The TRC-20/BEP-20/ERC-20 token **contract address** 3. **Amount** – The integer value in the token’s **smallest unit (raw amount)** > **Precision Example** @@ -114,7 +130,7 @@ x402 supports four payment schemes. Each is implemented as a client + server + f The `exact` scheme pays the exact amount advertised. It covers two token transfer paths: -- **ERC-3009 `transferWithAuthorization`** — for tokens that natively support it (e.g. BSC testnet DHLU). Gasless: no `approve` needed; the client signs a typed-data authorization and the facilitator calls `transferWithAuthorization` on-chain. +- **EIP-3009 `transferWithAuthorization`** — for tokens that natively support it (e.g. official Base USDC and BSC testnet DHLU). Gasless: no `approve` needed; the client signs a typed-data authorization and the facilitator calls `transferWithAuthorization` on-chain. - **Permit2** — for plain ERC-20 / TRC-20 tokens that do not implement ERC-3009 (e.g. BSC USDC/USDT, TRON USDT/USDD). The client signs a Permit2 witness and the facilitator settles via the `x402ExactPermit2Proxy` contract. A one-time `approve(Permit2)` is required; the client auto-broadcasts it on first payment. The `exact` scheme conforms to the **v2 wire format** published by the **x402 Foundation**: a stock v2 client can pay a protected endpoint on this SDK's server directly, and this SDK's client can pay any v2-compliant server — no project-specific translation required. Transfer authorization data is carried in `payload.authorization`. @@ -174,8 +190,8 @@ You may deploy your own Facilitator to gain full control over payment verificati ### Deployment Requirements -- **Node Access** – Reliable RPC access (e.g. TronGrid or a public BSC endpoint) -- **Gas Funding** – A wallet with sufficient **TRX/BNB** to cover settlement gas fees +- **Node Access** – Reliable RPC access (e.g. TronGrid or an EVM JSON-RPC endpoint for BSC/Base) +- **Gas Funding** – A wallet with sufficient **TRX/BNB/ETH** to cover settlement gas fees - **Service Deployment** – Run the example facilitator from `examples/typescript/facilitator/basic` > For detailed configuration and API references, see the [Facilitator](./facilitator.md) documentation and the [Quickstart for Sellers](../getting-started/quickstart-for-sellers.md). @@ -184,10 +200,10 @@ You may deploy your own Facilitator to gain full control over payment verificati ## Quick Reference -| Core Component | TRON/BSC Implementation | +| Core Component | TRON/BSC/Base Implementation | | :------------- | :---------------------- | -| **Networks** | `tron:0x2b6653dc`, `tron:0x94a9059e`, `tron:0xcd8690dc`, `eip155:56`, `eip155:97` | -| **Token Standard** | TRC-20 (built-in USDT & USDD support), BEP-20 | +| **Networks** | `tron:0x2b6653dc`, `tron:0x94a9059e`, `tron:0xcd8690dc`, `eip155:56`, `eip155:97`, `eip155:8453`, `eip155:84532` | +| **Token Standard** | TRC-20 (built-in USDT & USDD support), BEP-20, ERC-20 (Base official USDC) | | **Signing Mechanism** | TIP-712 / EIP-712 typed data signing | | **Payment Schemes** | `exact`, `upto`, `batch-settlement`, `exact_gasfree` (TRON) | @@ -216,11 +232,11 @@ Once registered, you can use the custom token symbol in TRON prices (e.g., `"0.0 ## Summary -x402 is deeply tailored for blockchain-native architectures, providing seamless TRC-20/BEP-20 integration and secure signature support. +x402 is deeply tailored for blockchain-native architectures, providing seamless TRC-20/BEP-20/ERC-20 integration and secure signature support. ### Key Takeaways - **Development Environment**: Use testnets for development and debugging. -- **Default Settlement Asset**: **USDT** is the primary default token with preconfigured SDK support. +- **Default Settlement Asset**: TRON/BSC routes use their configured stablecoins; Base uses official **USDC**. - **Security Model**: TIP-712 / EIP-712 typed data signing ensures secure, trust-minimized payment authorization. - **Extensibility**: Expand support for any custom TRC-20/BEP-20 token via the TRON token registry (`registerToken`) or the server's `EVM_TOKENS` config table. diff --git a/docs/x402/faq.md b/docs/x402/faq.md index bf96a6de..52ae0e16 100644 --- a/docs/x402/faq.md +++ b/docs/x402/faq.md @@ -7,7 +7,7 @@ import TabItem from '@theme/TabItem'; #### What is x402 in one sentence? -x402 revives the long-unused HTTP `402 Payment Required` status code and transforms it into a fully functional on-chain payment layer designed for APIs, websites, and autonomous AI agents. It is currently supported on TRON and BSC, with plans to expand to additional blockchain networks in the future. +x402 revives the long-unused HTTP `402 Payment Required` status code and transforms it into a fully functional on-chain payment layer designed for APIs, websites, and autonomous AI agents. It currently supports TRON, BSC, and Base, with plans to expand to additional blockchain networks in the future. #### Is x402 a commercial product? @@ -70,7 +70,7 @@ Common pricing models include: x402 supports four payment schemes: -- **`exact`**: Pay the exact advertised amount. ERC-3009 tokens (e.g. BSC testnet DHLU) settle gaslessly via `transferWithAuthorization`; plain ERC-20/TRC-20 tokens (e.g. BSC USDC/USDT, TRON USDT/USDD) settle via the Permit2 path with a one-time `approve(Permit2)`. The `exact` wire payload conforms to the **x402 Foundation** v2 spec. +- **`exact`**: Pay the exact advertised amount. EIP-3009 tokens (e.g. official Base USDC and BSC testnet DHLU) settle gaslessly via `transferWithAuthorization`; plain ERC-20/TRC-20 tokens (e.g. BSC USDC/USDT, TRON USDT/USDD) settle via the Permit2 path with a one-time `approve(Permit2)`. The `exact` wire payload conforms to the **x402 Foundation** v2 spec. - **`upto`**: Usage-based billing — the client signs a Permit2 authorization for up to a **maximum**; the server settles only the **real usage** (≤ max). Ideal for **metered billing**, **LLM token usage**. - **`batch-settlement`**: Payment-channel for high-frequency micro-payments — deposit once, pay many requests with off-chain vouchers, settle in one batch tx. Includes a refund path. - **`exact_gasfree`** (TRON only): Allows buyers to pay with USDT/USDD without holding TRX for gas. A relayer pays the on-chain energy via the GasFree API — no API keys required on the client side. @@ -83,6 +83,7 @@ x402 supports four payment schemes: - This SDK's client can pay v2-compatible servers directly. - In the V2 structure, transfer authorization data is carried in the `payload.authorization` field (a structured object). As a migration fallback, the client also populates `extensions.transferAuthorization` so that servers still running older versions can parse the payload. - BSC USDT/USDC are plain ERC-20s (no ERC-3009). They settle via the Permit2 path under the `exact` scheme — the client auto-broadcasts a one-time `approve(Permit2)` on first payment. ERC-3009 tokens like BSC testnet **DHLU** settle gaslessly with no approve. +- Base Mainnet official USDC uses EIP-3009 under `exact`: the payer signs `transferWithAuthorization`, so no Permit2 approval is required. - The `examples/bsc-testnet-smoke/` directory contains smoke tests for bidirectional interoperability (Coinbase official client → BANK OF AI server, BANK OF AI client → Coinbase official server) that you can use as a debugging and integration reference. --- @@ -103,6 +104,8 @@ x402 supports four payment schemes: | BSC Testnet (`eip155:97`) | USDT (BEP-20) | **Testnet** | | BSC Testnet (`eip155:97`) | USDC (BEP-20) | **Testnet** | | BSC Testnet (`eip155:97`) | DHLU (BEP-20, for `exact` interop tests) | **Testnet** | +| Base Mainnet (`eip155:8453`) | Official USDC (ERC-20, EIP-3009) | **Mainnet** | +| Base Sepolia (`eip155:84532`) | USDC (ERC-20, EIP-3009) | **Testnet** | Custom TRC-20 tokens can be added via the TRON token registry (`registerToken` from `@bankofai/x402-tron`); custom BEP-20 tokens are advertised by adding an entry to the server's `EVM_TOKENS` config table. @@ -111,6 +114,7 @@ Custom TRC-20 tokens can be added via the TRON token registry (`registerToken` f - **Network Fees**: - TRON: TRX for Energy and Bandwidth (paid by the Facilitator) - BSC: BNB for gas (paid by the Facilitator) + - Base: ETH for gas (paid by the Facilitator) - **Facilitator Service Fee**: Configurable by each Facilitator (can be set to zero) --- diff --git a/docs/x402/getting-started/quickstart-for-sellers.md b/docs/x402/getting-started/quickstart-for-sellers.md index 91f29225..29f1785c 100644 --- a/docs/x402/getting-started/quickstart-for-sellers.md +++ b/docs/x402/getting-started/quickstart-for-sellers.md @@ -84,6 +84,22 @@ You need a blockchain wallet address to receive tokens from users. Follow the st > ✅ **Success:** Wallet shows test BNB and test USDT balance greater than 0 + + + +**Create a Base Wallet (approx. 3 minutes):** + +1. Install [Coinbase Wallet](https://www.coinbase.com/wallet) or [MetaMask](https://metamask.io/) +2. Create a dedicated wallet and store its recovery phrase securely +3. Switch to Base Mainnet +4. Copy the `0x` wallet address that will receive USDC payments + +**Fund the payout wallet:** + +Deposit a small amount of official USDC on Base Mainnet. The resource server only publishes this address and never needs its private key. Mainnet payments use real funds. + +> ✅ **Success:** Wallet shows official Base USDC and the payout address starts with `0x` + @@ -100,24 +116,26 @@ You need a blockchain wallet address to receive tokens from users. Follow the st |--------|------|----------| | **TRON Wallet Address** | Wallet address starting with `T` (your payout address) | Copy from TronLink | | **BSC Wallet Address** | Wallet address starting with `0x` (your payout address) | Copy from MetaMask | +| **Base Wallet Address** | Wallet address starting with `0x` (your payout address) | Copy from Coinbase Wallet or MetaMask | | **Test TRX** | TRON testnet fee token | [Nile Faucet](https://nileex.io/join/getJoinPage) | | **Test USDT/USDD (TRON)** | TRON test payment token (both USDT and USDD supported) | [Nile Faucet](https://nileex.io/join/getJoinPage) | | **Test BNB** | BSC testnet fee token | [BSC Testnet Faucet](https://www.bnbchain.org/en/testnet-faucet) | | **Test USDT (BSC)** | BSC test payment token | [BSC Testnet Faucet](https://www.bnbchain.org/en/testnet-faucet) | +| **USDC (Base)** | Official Base Mainnet settlement token | Bridge or transfer official USDC to Base Mainnet | **Testnet vs. Mainnet:** - **Testnet**: Uses free test tokens, no real funds involved, suitable for development and debugging. Network identifiers: `tron:0xcd8690dc` / `eip155:97` -- **Mainnet**: Involves real payments, used when going live. Network identifiers: `tron:0x2b6653dc` / `eip155:56` +- **Mainnet**: Involves real payments, used when going live. Network identifiers: `tron:0x2b6653dc` / `eip155:56` / Base `eip155:8453` --- ## Step 1: Install the SDK Packages -Install the Express adapter and TRON payment scheme in your TypeScript API project: +Install the Express adapter and the TRON/EVM payment schemes in your TypeScript API project: ```bash -pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron +pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron @bankofai/x402-evm ``` Use the framework package that matches your server (`@bankofai/x402-express`, `@bankofai/x402-hono`, `@bankofai/x402-fastify`, or `@bankofai/x402-next`). Use `npm install` or `yarn add` with the same package names if your project does not use pnpm. @@ -133,7 +151,7 @@ The minimal server needs only two values: | Configuration | Description | Example | |------|------|------| | `HTTPFacilitatorClient.url` | Payment verification and settlement service URL | `https://facilitator.example.com` | -| `payTo` | Your TRON receiving address | `T...` | +| `payTo` | Your receiving address on the selected network | TRON: `T...`; BSC/Base: `0x...` | > 💡 **Keyless server:** The resource server never signs or holds a private key — it only advertises your public receiving address (`payTo`). Signing and settlement happen on the client and facilitator side. @@ -143,7 +161,10 @@ The minimal server needs only two values: ## Step 3: Create a Payment-Protected API Server -Here is a minimal Express resource server. `GET /credit` requires a `1 USDT` payment before it returns the credit payload. +Here are minimal Express resource servers for TRON and Base. `GET /credit` requires payment before it returns the credit payload. + + + ```typescript import express from "express"; @@ -190,13 +211,63 @@ express() .listen(4021); ``` + + + +```typescript +import express from "express"; +import { createResourceServer } from "@bankofai/x402-core"; +import { HTTPFacilitatorClient } from "@bankofai/x402-core/server"; +import { + x402HTTPResourceServer, + paymentMiddlewareFromHTTPServer, +} from "@bankofai/x402-express"; +import { ExactEvmScheme } from "@bankofai/x402-evm/exact/server"; + +const server = createResourceServer( + new HTTPFacilitatorClient({ + url: "https://facilitator.example.com", + }) +); + +server.register("eip155:8453", new ExactEvmScheme()); + +express() + .use( + paymentMiddlewareFromHTTPServer( + new x402HTTPResourceServer(server, { + "GET /credit": { + accepts: [ + { + scheme: "exact", + network: "eip155:8453", + payTo: "0x...", + price: "1 USDC", + }, + ], + }, + }) + ) + ) + .get("/credit", (_req, res) => + res.json({ + status: "success", + credit: 1000000, + }) + ) + .listen(4021); +``` + + + + **Key configuration parameters:** | Parameter | Description | Example | |------|------|--------| -| `payTo` | Your receiving wallet address | `T...` | -| `accepts[].price` | Price per request | `"1 USDT"` | -| `accepts[].network` | Network to use | Testnet: `TRON_NILE` (`tron:0xcd8690dc`) | +| `payTo` | Your receiving wallet address | TRON: `T...`; Base: `0x...` | +| `accepts[].price` | Price per request | TRON: `"1 USDT"`; Base: `"1 USDC"` | +| `accepts[].network` | Network to use | TRON Nile: `tron:0xcd8690dc`; Base Mainnet: `eip155:8453` | | `accepts[].scheme` | Payment scheme | `"exact"` | | `routes` | Map of `"METHOD /path"` → `{ accepts }` | `"GET /credit"` | diff --git a/docs/x402/index.md b/docs/x402/index.md index ee1bafb5..3bc0dd8f 100644 --- a/docs/x402/index.md +++ b/docs/x402/index.md @@ -9,7 +9,7 @@ description: >- x402 is an open blockchain payment standard built on the HTTP `402 Payment Required` status code. It enables web services to charge for APIs or content through a “pay-before-response” mechanism — without relying on traditional account systems or session management. -x402 currently supports the **TRON** and **BSC** networks, with plans to expand to a broader multi-chain ecosystem in the future. +x402 currently supports **TRON**, **BNB Smart Chain (BSC)**, and **Base**, with plans to expand to a broader multi-chain ecosystem in the future. **Interested in contributing to the documentation?** Feel free to submit a PR to the [GitHub repository](https://github.com/BofAI/docs). Our only principle is to maintain neutrality — aside from essential resource links, please avoid promotional or branded content. @@ -80,6 +80,9 @@ x402 currently supports the following networks: - **TRON Nile Testnet** (`tron:0xcd8690dc`) - **BSC Mainnet** (`eip155:56`) - **BSC Testnet** (`eip155:97`) +- **Base Mainnet** (`eip155:8453`) + +Base Mainnet payments use official USDC with the `exact` scheme and EIP-3009 authorization. > **SDK (TypeScript-only)**: x402 is a TypeScript-only SDK published as granular `@bankofai/x402-*` npm packages (`core`, `evm`, `tron`, `fetch`, `express`, `hono`, `fastify`, `next`, `axios`, `mcp`, `extensions`). The source is maintained in a pnpm/turbo monorepo, but application development should install the published packages. Supported schemes: `exact` (ERC-3009 / Permit2), `upto`, `batch-settlement`, and `exact_gasfree` (TRON). The previous-generation Python + TypeScript SDK lives under `legacy/` for reference. See the [SDK Feature Matrix](./sdk-features) for the full breakdown. diff --git a/docs/x402/sdk-features.md b/docs/x402/sdk-features.md index ce300cc3..a3a6ad19 100644 --- a/docs/x402/sdk-features.md +++ b/docs/x402/sdk-features.md @@ -55,8 +55,10 @@ This page tracks the feature support of the x402 SDK. | `tron:0x94a9059e` | `TRON_SHASTA` | ✅ | | `eip155:56` (BSC Mainnet) | - | ✅ | | `eip155:97` (BSC Testnet) | - | ✅ | +| `eip155:8453` (Base Mainnet) | - | ✅ | +| `eip155:84532` (Base Sepolia) | - | ✅ (CLI/SDK testing) | -> Upstream EVM chains (Base, Base Sepolia, MegaETH, Monad, Hyperliquid) are also wired in the EVM default-asset registry. Adding a chain is a config-table edit in the examples — no SDK changes. +> Other upstream EVM chains (MegaETH, Monad, Hyperliquid) are also wired in the EVM default-asset registry. The public API Catalog publishes Base Mainnet routes only; Base Sepolia remains available for CLI/SDK testing. --- @@ -141,6 +143,7 @@ Key custody is in [`@bankofai/agent-wallet`](https://github.com/BofAI/agent-wall | USDT (BEP-20) | `eip155:56`, `eip155:97` | ✅ | | USDC (BEP-20) | `eip155:56`, `eip155:97` | ✅ | | DHLU (BSC testnet, ERC-3009) | `eip155:97` | ✅ | +| Official USDC (ERC-20, EIP-3009) | `eip155:8453`, `eip155:84532` | ✅ | | Custom TRC-20 / BEP-20 | any | ✅ (via token registry / `EVM_TOKENS` config) | --- diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/index.md b/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/index.md index b411ea7a..3ebc33e3 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/index.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/index.md @@ -7,6 +7,21 @@ description: 'BANK OF AI 各产品的更新与公告——全部产品,按时 BANK OF AI 各产品的更新与公告。 +
+
2026-07-30
+
+ +### x402 CLI v1.0.2 · Catalog —— 支持 Base + +
新版本x402Base
+ +- **CLI 已支持 Base**——`eip155:8453` 与 `eip155:84532` 均支持 USDC;服务目录目前只发布 `eip155:8453` Base 主网路由。Base 在 `exact` 方案下使用 EIP-3009 授权,而非 Permit2。 +- **Agent Wallet 成为 CLI 默认付款方**——`pay` 用你当前激活的钱包签名,私钥不再进环境变量。若配置了钱包但没有激活项,CLI 会在签名前停下而不是替你选。[详情](./x402/) +- 付费请求不再跟随 HTTP 重定向,避免 `PAYMENT-SIGNATURE` 流向其他源。 + +
+
+
2026-07-21
@@ -25,6 +40,20 @@ BANK OF AI 各产品的更新与公告。
+
+
2026-07-20
+
+ +### x402 CLI v1.0.1 · Catalog + +
新版本x402TRON
+ +- **x402 CLI v1.0.1**——TRON **GasFree** 支付(`exact_gasfree`,无需 TRX)、标准 CAIP-2 网络标识(旧的 `tron:nile` 被拒绝)、`settled` 与 `delivered` 状态区分。基于 x402 SDK 1.0.1。[详情](./x402/) +- **x402 Catalog**——目录路由现支持 TRON 上的 `exact_gasfree`;网络标识必须用标准 CAIP-2;旧的 `fee` / `feeConfig` 字段已移除。[详情](./x402/) + +
+
+
2026-07-17
diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/x402.md b/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/x402.md index 73df74e9..65faa74a 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/x402.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs-changelog/current/x402.md @@ -5,7 +5,78 @@ description: 'x402 支付协议、SDK 与 CLI 的版本发布记录。' # x402支付协议 -x402 协议、SDK 与 [CLI](../x402/cli/) 的版本发布记录。 +x402 协议、SDK 与 [CLI](/x402/cli/) 的版本发布记录。 + +
+
2026-07-30
+
+ +### x402 CLI v1.0.2 —— Base USDC 与 Agent Wallet + +
新版本CLIBase
+ +- **支持 Base**——`eip155:8453`(主网)与 `eip155:84532`(Sepolia),均支持 USDC,并提供 `base-mainnet` / `base-sepolia` 别名。Base 走标准 `exact` 方案,但使用 **EIP-3009** 授权而非 Permit2。生产环境请通过 `--rpc-url` 或 `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` 自备 RPC。 +- **Agent Wallet 成为默认付款方**——`pay` 会解析你当前激活的 [Agent Wallet](/Agent-Wallet/Intro/) 并交由它签名,私钥不再需要放进环境变量。如果配置了钱包但没有激活项,CLI 会**在签名前停下**而不是替你选一个。可用 `--wallet-id` / `AGENT_WALLET_ID` 显式指定,或用 `AGENT_WALLET_DIR` 指向其他目录。私钥现在只作为开发/CI 的覆盖手段。 +- **付费请求不再跟随重定向**,确保 `PAYMENT-SIGNATURE` 不会被转发到其他源。 +- **EVM 余额预检**——签名前校验付款方代币余额,并返回解析出的钱包 ID、地址与原始余额。 +- 新增:`pay --asset` / `--decimals`、`serve --valid-for-seconds`(默认 `300`),以及 `roundtrip --json` 输出单个文档、内含独立的 `serve` 与 `pay` 结果。 +- 新增钱包类错误码:`WALLET_PASSWORD_REQUIRED`、`WALLET_DECRYPTION_FAILED`、`WALLET_CONFIG_CORRUPT`、`WALLET_NETWORK_ERROR`。 + +👉 [x402 CLI 文档](/x402/cli/) + +
+
+ +
+
2026-07-30
+
+ +### x402 Catalog —— Base 路由 + +
更新CatalogBase
+ +- 发布 `eip155:8453` **Base 主网目录路由**,配套支付指引与代码示例。CLI 仍支持 Base Sepolia,但服务目录未发布 Base Sepolia 路由。 +- `assetTransferMethod` 现在除 `permit2` 外还接受 **`eip3009`**——Base USDC 路由使用 `eip3009`。 + +👉 [API Catalog 参考](/x402/api-catalog/reference/) + +
+
+ +
+
2026-07-20
+
+ +### x402 CLI v1.0.1 + +
新版本CLITRON
+ +- **TRON GasFree 支付(`exact_gasfree`)**——由 relayer 代付网络能量、并从支付代币里扣除手续费,付款方无需 TRX。新增参数:`--scheme exact_gasfree`、`--max-gasfree-fee`、`--max-gasfree-fee-raw`、`--gasfree-api-url`。 +- **标准 CAIP-2 网络标识**——`tron:0x2b6653dc`(主网)、`tron:0xcd8690dc`(Nile)、`tron:0x94a9059e`(Shasta)。旧标识如 `tron:nile` / `tron:mainnet` 现已被**拒绝**,CLI 会提示应改用的标准标识。 +- **结算状态**——已付款响应区分 `settled`(支付已在链上结算)与 `delivered`(上游 HTTP 响应成功)。 +- 基于 x402 SDK 1.0.1 构建。 + +👉 [x402 CLI 文档](/x402/cli/) + +
+
+ +
+
2026-07-20
+
+ +### x402 Catalog —— GasFree 路由与 CAIP-2 + +
更新Catalog
+ +- 目录路由现已支持 TRON 上的 **`exact_gasfree`**,与 `exact` + Permit2 并存。 +- 网络标识必须使用**标准 CAIP-2**;旧的 TRON 别名如 `tron:nile` 会被 schema 校验拒绝。 +- 在 x402 SDK 1.0.1 下,GasFree 费用由客户端估算——目录路由不再发布旧的 `fee` / `feeConfig` 字段。 + +👉 [API Catalog 参考](/x402/api-catalog/reference/) + +
+
2026-07-15
@@ -24,7 +95,7 @@ x402 协议、SDK 与 [CLI](../x402/cli/) 的版本发布记录。 - 基于已发布的 `@bankofai/x402-core` / `x402-evm` / `x402-tron` SDK 1.0 包构建;`scheme=exact` 配合 Permit2 - 支持网络:TRON(`tron:mainnet` / `tron:nile` / `tron:shasta`)与 BSC(`eip155:56` / `eip155:97`) -👉 立即上手:[x402 CLI 快速开始](../x402/cli/quickstart/) +👉 立即上手:[x402 CLI 快速开始](/x402/cli/quickstart/)
diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/CLI-Reference.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/CLI-Reference.md index 2ae191aa..5bd4e0e6 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/CLI-Reference.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/CLI-Reference.md @@ -58,6 +58,33 @@ agent-wallet start -p Abc12345! -k 你的私钥十六进制 agent-wallet start -p Abc12345! -m "word1 word2 word3 ..." ``` +#### 跳过交互:直接指定钱包类型 + +`start` 和 `add` 也可以把钱包类型作为子命令传入。这种形式不会有任何提问——正是 CI 或后台服务需要的: + +```bash +agent-wallet start local_secure -p Abc12345! -g # 加密存储,生成新私钥 +agent-wallet start raw_secret -k 你的私钥 # 明文,仅限开发 +agent-wallet start privy --app-id --app-secret --privy-wallet-id +``` + +`add` 用法相同(`add local_secure` / `add raw_secret` / `add privy`),用于再加一个钱包。 + +| 选项 | 适用类型 | 说明 | +| :--- | :--- | :--- | +| `-w, --wallet-id ` | 全部 | 要创建的钱包 ID | +| `-g, --generate` | `local_secure` | 生成一个新的随机私钥 | +| `-k, --private-key ` | `local_secure`、`raw_secret` | 导入私钥 | +| `-m, --mnemonic ` | `local_secure`、`raw_secret` | 导入助记词 | +| `--mnemonic-index ` | `local_secure`、`raw_secret` | 从助记词派生时的账户索引 | +| `-p, --password ` | `local_secure` | 主密码 | +| `--app-id` / `--app-secret` / `--privy-wallet-id` | `privy` | Privy 应用凭证与钱包 ID | +| `-d, --dir ` | 全部 | 密钥目录(默认 `~/.agent-wallet`) | +| `--save-runtime-secrets` | 全部 | 把密码写入 `runtime_secrets.json` | +| `--override` | 仅 `start` | 覆盖已有配置 | + +用 `agent-wallet start local_secure --help` 或 `agent-wallet add privy --help` 查看某个模式的确切选项。 + ### `agent-wallet sign`(核心签名操作) 每条 `sign` 子命令都需要 `--network` / `-n` 来指定链。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/SDK-Guide.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/SDK-Guide.md index 7a1c32c5..caf51c92 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/SDK-Guide.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/Agent-Wallet/Developer/SDK-Guide.md @@ -195,6 +195,10 @@ export AGENT_WALLET_MNEMONIC='word1 word2 word3 ...' | `AGENT_WALLET_MNEMONIC` | 明文助记词短语 | ⚠️ 静态注入 | 二选一(与私钥) | | `AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX` | BIP-44 派生索引(默认 `0`) | ⚠️ 静态注入 | 可选 | +:::note 遗留变量名 +SDK 仍然接受早期的 `TRON_PRIVATE_KEY`、`TRON_MNEMONIC`、`TRON_ACCOUNT_INDEX`,它们分别对应 `AGENT_WALLET_PRIVATE_KEY`、`AGENT_WALLET_MNEMONIC`、`AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX`。虽然名字里带 TRON,但在 EVM 网络上同样生效。新项目建议统一用 `AGENT_WALLET_*` 这套名字。 +::: + --- ## 使用示例 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/AGENTS.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/AGENTS.md index 4c54c818..6506f949 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/AGENTS.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/AGENTS.md @@ -65,7 +65,7 @@ import TabItem from '@theme/TabItem'; - **测试示例**:Nile 测试网 USDT 地址为 `TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf`。 - + - **网络标识**:必须遵循 `eip:` 格式。 - **签名标准**:BSC 签名完全兼容以太坊 **EIP-712** 标准(无需特殊适配,直接使用通用 EVM 签名库)。 @@ -73,6 +73,15 @@ import TabItem from '@theme/TabItem'; - **节点接入**:节点访问需指向兼容 EVM 的 JSON-RPC 端点。 - **测试示例**:BSC Testnet 模拟 USDT 地址为 `0x337610d27c682E347C9cD60BD4b3b107C9d34dDd`。 + + + +- **Network Identifier**: Base Mainnet must use canonical CAIP-2 ID `eip155:8453`. +- **Settlement Asset**: Use official Base USDC at `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`. +- **Payment Scheme**: Use `exact` with EIP-3009 authorization; do not describe Base USDC as Permit2. +- **Address Format**: Payout and token addresses use EVM hexadecimal (`0x`) format. +- **Catalog Scope**: Public catalog examples use Base Mainnet only. Base Sepolia (`eip155:84532`) may appear only in explicit CLI/SDK testing documentation. + diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/get-started.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/get-started.md index 1ea76cfe..a0cfb6d9 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/get-started.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/get-started.md @@ -12,7 +12,7 @@ description: 3 分钟把你的 Agent 接入 API 目录 —— 安装 Agent Walle ## 第 1 步:安装 Agent Wallet -运行下面这行命令,你会装上一个在 TRON 与 BNB Chain 上管理稳定币的本地钱包。之后 Agent 发起的每一次付费调用,都由它在本地签名。 +运行下面这行命令,你会装上一个在 TRON、BNB Chain 与 Base 上管理稳定币的本地钱包。之后 Agent 发起的每一次付费调用,都由它在本地签名。 ```bash npm i -g @bankofai/agent-wallet @@ -73,8 +73,8 @@ x402-cli pay 'https://x402-gateway.bankofai.io/providers//' \ | 参数 | 作用 | |---|---| | `--method` | HTTP 方法(默认 `GET`) | -| `--network` | CAIP-2 支付链,如 `tron:0x2b6653dc`、`eip155:56` | -| `--token` | 结算代币,如 `USDT` | +| `--network` | CAIP-2 支付链,如 `tron:0x2b6653dc`、`eip155:56`、`eip155:8453` | +| `--token` | 结算代币,如 `USDT` 或 Base 主网 `USDC` | | `--scheme` | 路由声明的 x402 支付方案,如 `exact` | | `--max-amount` | 美元支出上限;报价超出即中止调用 | | `--header` / `--body` | 转发到上游的请求头与请求体 | diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/index.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/index.md index 60771c4b..b0948923 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/index.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/index.md @@ -8,7 +8,7 @@ description: BANK OF AI 的钱包原生服务目录 —— AI Agent 在这里发 传统 API 的门槛是为人设计的:注册账号、申请 API Key、绑定信用卡、按月订阅。可一个 AI Agent 想自主调用一个接口时,光是「开户」这一步就走不通——它没有邮箱、没有信用卡,也不该替你保管一长串密钥。 -**API 目录**(API Catalog)是 BANK OF AI 的钱包原生服务目录。AI Agent 在这里发现服务、按名称调用、按次付费,每一笔调用都通过 x402 在链上结算。没有账号,没有 API Key,**钱包即身份**。目录同时覆盖 TRON 与 BNB Chain。 +**API 目录**(API Catalog)是 BANK OF AI 的钱包原生服务目录。AI Agent 在这里发现服务、按名称调用、按次付费,每一笔调用都通过 x402 在链上结算。没有账号,没有 API Key,**钱包即身份**。目录覆盖 TRON、BNB Chain 和 Base 主网。 ## 它解决什么 @@ -41,7 +41,7 @@ pay.md 构建静态快照 dist/ /api/providers/< ## 目录里有什么 -首批上线服务覆盖发币、DeFi 市场数据与链上安全 —— 全部支持 TRON 与 BNB Chain 结算,后续会陆续增加: +首批上线服务覆盖发币、DeFi 市场数据与链上安全;每个服务根据其已发布路由支持 TRON、BNB Chain 或 Base 主网结算: | 服务 | 它能做什么 | 计费 | |---|---|---| @@ -51,7 +51,7 @@ pay.md 构建静态快照 dist/ /api/providers/< | DIA | 去中心化、多源预言机价格,按符号或链 + 合约地址查询 | $0.000001 / 次 | | GoPlus | 代币与地址安全检测 —— 蜜罐/诈骗筛查、恶意地址与高风险授权识别 | $0.000001 / 次 | -以上服务均属 **金融(Finance)** 类目,TRON 与 BNB Chain 均可用。 +以上服务均属 **金融(Finance)** 类目。请查看各端点的 `x402Routes`,确认当前已发布的 TRON、BNB Chain 和 Base 主网路由。 :::note 在架服务清单与统计数字(服务数、链数等)均由目录数据**动态生成**,以 `/api/catalog.json` 的实时内容为准,本文不写死具体数量;目录会随新服务上架而增长。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/list-your-service.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/list-your-service.md index c471e2c3..1515f987 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/list-your-service.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/list-your-service.md @@ -8,7 +8,7 @@ description: 把你的 API 上架到 API 目录 —— 填表申请或直接提 上架一次,此后每一次 AI Agent 调用都是一笔入账。 -把你的 API 接到网关之后,它就会出现在目录里:任意 Agent 都能发现它、调用它、为它付费。款项实时结算到你指定的钱包,**无平台托管、无结算周期**;可在 TRON 或 BNB Chain 上结算;现有 API 保持原样,**无需改动任何代码**,定价也由你自己说了算。 +把你的 API 接到网关之后,它就会出现在目录里:任意 Agent 都能发现它、调用它、为它付费。款项实时结算到你指定的钱包,**无平台托管、无结算周期**;可在 TRON、BNB Chain 或 Base 主网上结算;现有 API 保持原样,**无需改动任何代码**,定价也由你自己说了算。 ## 先看懂全景:上架到底是在做什么 @@ -233,7 +233,7 @@ CI 会强制以下规则,建议提交前逐条对照: - `version` 必须为 `1`。 - `fqn` 为小写字母/数字/连字符,且与目录名一致。 - `category` 必须是合法类目之一(见[参考](./reference.md#合法类目))。 -- `chains` 至少一条,使用 CAIP-2 风格的链 ID —— 主网或测试网均可(如 `tron:0x2b6653dc`、`tron:0xcd8690dc`、`eip155:56`、`eip155:97`)。 +- `chains` 至少一条,使用 CAIP-2 风格的链 ID。公开目录发布主网路由,例如 `tron:0x2b6653dc`、`eip155:56` 和 Base 主网 `eip155:8453`。 - `isFirstParty`、`isFeatured`(布尔值)与 `featuredTags`(字符串数组,可为空 `[]`)为**必填**,缺一即校验失败。 - 每个 endpoint 的 `method` 必须大写、`path` 以 `/` 开头、`maxPriceUsd` 不小于 `minPriceUsd`。 - _(选填)_ 跨多条链结算的端点可加 `x402Routes`,每个网络一条(`network`、`provider`、`scheme`、`url`)。详见[参考](./reference.md#x402routes--多网络路由)。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/reference.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/reference.md index 799ee44e..c1d50591 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/reference.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/api-catalog/reference.md @@ -60,14 +60,19 @@ description: catalog.json / pay.md 的字段定义、合法类目与链 ID,以 | 字段 | 类型 | 说明 | |---|---|---| -| `network` | string | 该路由结算所在的 CAIP-2 链 ID(如 `tron:0x2b6653dc`、`eip155:56`) | +| `network` | string | 该路由结算所在的标准 CAIP-2 链 ID(如 `tron:0x2b6653dc`、`eip155:56`、`eip155:8453`)。旧的 TRON 别名如 `tron:nile` 会被 schema 校验拒绝。 | | `provider` | string | 处理该网络的 gateway provider `fqn` | -| `scheme` | string | 该路由的 x402 支付方案,如 `exact` —— 由每条路由各自声明 | +| `scheme` | string | 该路由的 x402 支付方案:`exact`,或在 TRON 上 `exact_gasfree` —— 由每条路由各自声明 | +| `assetTransferMethod` | string | `exact` 路由使用的授权方式:TRON 与 BSC 填 `permit2`,Base USDC 填 `eip3009`;`exact_gasfree` 路由**不要**带该字段。 | | `url` | string | 该网络路由的完整 gateway URL | 构建时该字段以 `x402_routes` 透传到产物。存在时,调用方/Agent 按目标支付链选择对应路由;顶层 `url` 仍是默认路由。 -例如一个发币端点可能为每条支持的链各提供一条路由 —— TRON 主网与 BSC 主网,各有自己的 `provider` 和 `scheme`。调用时把 `x402-cli pay` 指向所选路由的 `url`,并传入匹配的 `--network` / `--scheme`: +:::note GasFree 路由 +在 TRON 上,可以为同一端点在 `exact` 路由之外再加一条 `exact_gasfree` 路由:由 relayer 代付网络能量、并从支付代币里扣除手续费,付款方无需 TRX。GasFree 路由仅限 TRON,且不能带 `assetTransferMethod`。在 x402 SDK 1.0.1 下,relayer 费用由客户端估算,因此目录路由**不得**再发布旧的 `fee` 或 `feeConfig` 字段。 +::: + +例如一个端点可以为每条支持的链各提供一条路由 —— TRON 主网、BSC 主网和 Base 主网,各有自己的 `provider` 和 `scheme`。调用时把 `x402-cli pay` 指向所选路由的 `url`,并传入匹配的 `--network` / `--scheme`: ```bash x402-cli pay 'https://x402-gateway.bankofai.io/providers//' \ @@ -116,6 +121,7 @@ security shopping storage translation | TRON Shasta 测试网 | `tron:0x94a9059e` | | BNB Chain (BSC) | `eip155:56` | | BNB 测试网 | `eip155:97` | +| Base 主网 | `eip155:8453` | 构建时会把每个链 ID 解析为展示元数据(`kind` / `label` / `label_zh`),前端无需自己解析 CAIP-2 —— 见[前端展示字段](#前端展示字段)。 @@ -185,7 +191,7 @@ CI 构建后生成静态快照 `dist/`,由 Catalog Server 通过 `/api/` 路 | `sub_title` | 次级展示行(取自 `subTitle`,回退到 `subtitle`) | | `sub_title_zh` | 中文次级展示行(取自 `i18n.zh-CN.subtitle` / `subTitle`,回退到 `subtitle`) | | `category_meta` | 类目的 `{ id, label, label_zh }` | -| `chain_kinds` | 去重后的友好链类型,如 `["tron"]`、`["bnb"]` | +| `chain_kinds` | 去重后的友好链类型,如 `["tron"]`、`["bnb"]`、`["base"]` | | `chains_meta` | 每条链的 `{ id, kind, label, label_zh }`,前端无需解析 CAIP-2 | 这些是增量字段 —— 原始的 `title`、`subtitle`、`category`、`chains`、`i18n.zh-CN` 依然保留。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/command-reference.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/command-reference.md index 1b44cf8c..abcf45f0 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/command-reference.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/command-reference.md @@ -46,18 +46,35 @@ x402-cli pay [options] | `--method ` | HTTP 方法(默认:`GET`) | | `--header "Name: Value"` | 请求头,可重复 | | `--body ` | 非 `GET`/`HEAD` 方法的请求体 | -| `--network ` | 要求特定网络(如 `tron:nile`) | -| `--token ` | 要求特定代币(如 `USDT`) | -| `--scheme ` | 要求特定 x402 scheme(如 `exact`) | +| `--network ` | 要求特定网络(如 `tron:0xcd8690dc`、`base-mainnet`) | +| `--token ` | 要求特定代币(如 `USDT`、`USDC`) | +| `--asset
` | 要求特定资产合约地址 | +| `--decimals ` | 未注册资产的精度 | +| `--scheme ` | 要求特定 x402 scheme:`exact` 或 `exact_gasfree` | +| `--gasfree-api-url ` | 覆盖 TRON GasFree relayer API 地址(环境变量 `X402_GASFREE_API_URL`) | +| `--max-gasfree-fee ` | GasFree relayer 手续费上限(代币单位) | +| `--max-gasfree-fee-raw ` | GasFree relayer 手续费上限(最小单位) | | `--max-amount ` | 允许支付的最大人类可读金额 | | `--max-raw-amount ` | 允许支付的最大最小单位金额 | | `--dry-run` | 只读取支付要求,不签名、不付款 | -| `--private-key ` | 显式付款方私钥(或用下方环境变量) | +| `--wallet-id ` | 显式指定已配置的 Agent Wallet(环境变量 `AGENT_WALLET_ID`) | +| `--private-key ` | 覆盖 Agent Wallet——仅限开发与 CI | | `--rpc-url ` | 显式网络 RPC URL | | `--timeout-ms ` | 网络超时(毫秒,默认:`30000`) | | `--json` | 打印结构化 JSON 输出 | -付款方私钥来自 `--private-key`,或环境变量:TRON 网络用 `TRON_PRIVATE_KEY`,EVM 网络用 `EVM_PRIVATE_KEY`,`PRIVATE_KEY` 作为两种网络通用的回退。 +已注册代币的精度以注册表为准,不能用 `--decimals` 覆盖。只有未注册的非 Base 资产,才需要同时传 `--asset` 和 `--decimals`。 + +### 用 Agent Wallet 付款 {#paying-with-agent-wallet} + +默认情况下,`pay` 会为所选网络解析出**当前激活的 [Agent Wallet](../../Agent-Wallet/Intro.md)** 并交由它签名——不需要把私钥放进配置文件或环境变量。 + +- 如果配置了钱包但没有激活项,CLI 会**在签名前停下**,而不是默认选第一个。请设置激活钱包,或用 `--wallet-id` / `AGENT_WALLET_ID` 显式指定。 +- 用 `AGENT_WALLET_DIR` 指向非默认的 Agent Wallet 目录。 +- CLI 不会从 `wallets_config.json` 里读取私钥。 +- 在 EVM 网络上,它会在签名前检查付款方的代币余额,并在结果中返回解析出的钱包 ID、地址与原始余额。EIP-712 的付款方必须与该地址一致。 + +**仅在开发与 CI 场景下**,可以用 `--private-key` 或 `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` 环境变量覆盖 Agent Wallet。共享环境中优先用环境变量而非命令行参数——命令行参数可能被本机其他进程看到。 **示例:** @@ -68,8 +85,8 @@ x402-cli pay https://api.example.com/paid --dry-run --json ```bash # 支付,但绝不超过 0.01 USDT -TRON_PRIVATE_KEY= x402-cli pay https://api.example.com/paid \ - --network tron:nile --token USDT --max-amount 0.01 +x402-cli pay https://api.example.com/paid \ + --network tron:0xcd8690dc --token USDT --max-amount 0.01 ``` ```bash @@ -80,6 +97,59 @@ x402-cli pay https://api.example.com/paid \ 如果接口没有返回 `402`,CLI 会报告实际状态与响应,而不会付款。 +### GasFree 支付(TRON) {#gasfree-payments-tron} + +在 TRON 上,`scheme=exact_gasfree` 让一个 relayer 代付网络能量、并从支付代币里扣除手续费,付款方无需持有 TRX。当服务端的 `402` 支付要求宣告了该 scheme 时,CLI 通常会自动选用;也可以用 `--scheme exact_gasfree` 显式要求。 + +GasFree 手续费与宣告的支付金额是**分开**的。设一个手续费上限,CLI 会先估算 relayer 手续费,若估值过高则在签名前拒绝: + +```bash +x402-cli pay https://api.example.com/pay \ + --network tron:0xcd8690dc --token USDT \ + --scheme exact_gasfree \ + --max-amount 0.01 \ + --max-gasfree-fee 0.5 \ + --json +``` + +`--max-gasfree-fee` 与 `--max-gasfree-fee-raw` 互斥,且仅对 `exact_gasfree` 支付要求生效。用 `--gasfree-api-url ` 或 `X402_GASFREE_API_URL` 覆盖 relayer 地址。 + +已付款的响应会区分 `settled`(支付已在链上结算)与 `delivered`(上游 HTTP 业务响应成功)。一次"结算成功但上游失败"的情况会返回 `paid=true`、`settled=true`、`delivered=false`,并仍带上交易信息——重试前请先核查交易与 provider 行为。 + +### 在 Base 上付款 {#paying-on-base} + +Base 通过标准的 `exact` EVM 流程结算 USDC,使用的是 **EIP-3009**(`transferWithAuthorization`)而非 Permit2。这一点不需要你选择——CLI 会按网络自动采用正确的授权方式。 + +```bash +x402-cli pay https://api.example.com/pay \ + --network base-mainnet \ + --token USDC \ + --max-amount 0.01 \ + --rpc-url <生产环境-RPC-地址> +``` + +内置的公共 RPC 仅供开发使用。生产环境请通过 `--rpc-url`,或 `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` / `EVM_RPC_URL` 提供 RPC 端点。 + +:::caution 不跟随重定向 +探测请求与带签名的重试都**不会**自动跟随 HTTP 重定向,以确保 `PAYMENT-SIGNATURE` 不被转发到其他源。如果接口发生重定向,请先确认目标地址,再显式请求最终可信的 URL。 +::: + +### 环境变量 {#pay-environment-variables} + +有些配置没有对应的命令行参数,只能通过环境变量设置: + +| 变量 | 用途 | +| :--- | :--- | +| `AGENT_WALLET_DIR` | 使用非默认的 Agent Wallet 目录 | +| `AGENT_WALLET_ID` | 指定已配置的钱包(等同 `--wallet-id`) | +| `TRON_RPC_URL` | TRON RPC 地址(`--rpc-url` 未传时使用) | +| `TRON_GRID_API_KEY` | TronGrid API Key——设置后可避免公共节点限流 | +| `X402_TRON_ALLOWANCE_MODE` | TRON 授权额度处理方式,默认 `auto` | +| `EVM_RPC_URL` | 默认 EVM RPC 地址 | +| `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` | Base 主网 / Base Sepolia 的专用 RPC | +| `X402_GASFREE_API_URL` | 覆盖 TRON GasFree relayer 接口地址 | +| `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` | 覆盖 Agent Wallet——仅限开发与 CI | + --- ## `serve` @@ -95,7 +165,8 @@ x402-cli serve --pay-to
[options] | `--pay-to
` | **(必填)** 收款钱包地址 | | `--amount ` | 人类可读的代币金额(默认:`0.0001`) | | `--raw-amount ` | 最小单位金额(与 `--amount` 互斥) | -| `--network ` | 支付网络(默认:`tron:nile`) | +| `--network ` | 支付网络(默认:`tron:0xcd8690dc`) | +| `--scheme ` | 支付 scheme:`exact` 或 `exact_gasfree`(默认:`exact`) | | `--token ` | 代币符号(默认:`USDT`) | | `--asset
` | 未注册代币的显式合约地址 | | `--decimals ` | 代币精度,配合未注册的 `--asset` 时必填 | @@ -103,6 +174,7 @@ x402-cli serve --pay-to
[options] | `--port ` | 绑定端口(默认:`4020`) | | `--resource-url ` | 在支付要求中对外宣告的 URL | | `--facilitator-url ` | Facilitator 基础 URL(默认:`https://facilitator.bankofai.io`) | +| `--valid-for-seconds ` | 支付要求的有效时长(默认:`300`) | | `--timeout-ms ` | Facilitator 超时(毫秒,默认:`30000`) | | `-d, --daemon` | 在后台运行并打印子进程 pid | | `--json` | 打印结构化 JSON 输出 | @@ -119,7 +191,7 @@ x402-cli serve --pay-to
[options] **示例:** ```bash -x402-cli serve --pay-to T... --network tron:nile --token USDT +x402-cli serve --pay-to T... --network tron:0xcd8690dc --token USDT ``` ```bash @@ -139,10 +211,12 @@ x402-cli roundtrip --pay-to
[serve/pay 选项] **示例:** ```bash -TRON_PRIVATE_KEY= x402-cli roundtrip \ - --pay-to T... --amount 0.0001 --network tron:nile --token USDT +x402-cli roundtrip \ + --pay-to T... --amount 0.0001 --network tron:0xcd8690dc --token USDT ``` +加上 `--json` 时,`roundtrip` 会输出单个 JSON 文档,其中分别包含 `serve` 与 `pay` 的结果。 + --- ## `gateway` diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/faq.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/faq.md index effb5d1a..6553e491 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/faq.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/faq.md @@ -34,20 +34,23 @@ npm update -g @bankofai/x402-cli ### 使用 CLI 一定要钱包吗? -只有真正付款时才需要。只读命令——`pay --dry-run`、`catalog search`、`catalog show`、`gateway check`——都无需钱包。真正的 `pay` 或 `roundtrip` 才需要付款方私钥。 +只有真正付款时才需要。只读命令——`pay --dry-run`、`catalog search`、`catalog show`、`gateway check`——都无需钱包。真正的 `pay` 或 `roundtrip` 会用你当前激活的 [Agent Wallet](../../Agent-Wallet/Intro.md) 签名。 -### 如何提供私钥? +### CLI 怎么决定用哪个钱包签名? -设置以下环境变量之一: +它会为支付网络解析出**当前激活的 Agent Wallet**。如果配置了钱包但没有标记激活项,CLI 会在签名前停下、而不是替你猜——请设置激活钱包,或显式指定: -- **TRON 网络** → `TRON_PRIVATE_KEY` -- **EVM 网络**(BSC) → `EVM_PRIVATE_KEY` -- **两种网络通用** → `PRIVATE_KEY`,当没有设置对应网络的专用变量时作为回退 +- `--wallet-id ` 或 `AGENT_WALLET_ID` —— 指定某个已配置的钱包 +- `AGENT_WALLET_DIR` —— 使用非默认的 Agent Wallet 目录 -你也可以用 `--private-key ` 为单条命令传入,但请避免在共享 Shell 或提交到版本库的脚本里这样做——命令行参数会被记录到 Shell 历史和进程列表中。 +CLI 不会从 `wallets_config.json` 里读取私钥。在 EVM 网络上,它还会在签名前检查付款方的代币余额,并在结果中返回解析出的钱包 ID、地址与原始余额。 + +### 还能用裸私钥吗? + +可以,但仅限开发与 CI:`--private-key `,或 `EVM_PRIVATE_KEY` / `TRON_PRIVATE_KEY` / `PRIVATE_KEY` 环境变量。共享环境中请优先用环境变量而非命令行参数——后者会被记录到 Shell 历史和进程列表中。 :::caution -任何超出一次性测试范围的场景,请使用 [agent-wallet](../../Agent-Wallet/Intro.md) 付款钱包,而不是裸露的环境变量私钥;并且付款方地址里只保留当前任务所需的最小额度。 +任何超出一次性测试范围的场景,请使用 Agent Wallet 而不是裸私钥;并且付款方地址里只保留当前任务所需的最小额度。 ::: ### 支付会超出我的预期金额吗? @@ -56,7 +59,17 @@ npm update -g @bankofai/x402-cli ### 支持哪些网络和代币? -TRON(`tron:mainnet`、`tron:nile`、`tron:shasta`)与 BSC(`eip155:56`、`eip155:97`),并按网络内置 USDT、USDD、USDC 的注册表。完整表格见 [x402 CLI 概览](./index.md#支持的网络与代币)。若代币未注册,用 `--asset
` 搭配 `--decimals `。 +TRON(`tron:0x2b6653dc`、`tron:0xcd8690dc`、`tron:0x94a9059e`)、BSC(`eip155:56`、`eip155:97`)与 Base(`eip155:8453`、`eip155:84532`),并按网络内置 USDT、USDD、USDC 的注册表。完整表格见 [x402 CLI 概览](./index.md#支持的网络与代币)。已注册代币的精度以注册表为准;只有未注册的非 Base 资产,才需要用 `--asset
` 搭配 `--decimals `。 + +TRON 网络必须传标准的 CAIP-2 标识符(`tron:0x…`)。旧标识如 `tron:nile`、`tron:mainnet`、`mainnet` 等已不再被接受——CLI 会拒绝并提示应改用的标准标识符。EVM 别名(`bsc-mainnet`、`bsc-testnet`、`base-mainnet`、`base-sepolia`)仍可使用。 + +### 在 Base 上付款有什么不同? + +Base 结算 USDC 用的是 **EIP-3009**(`transferWithAuthorization`)而非 Permit2,但仍属于 `exact` 方案。这一点不需要你配置——CLI 会按网络自动采用正确的授权方式。唯一需要你自己设置的是 RPC:内置的公共端点仅供开发使用,生产环境请传 `--rpc-url`,或设置 `EVM_RPC_URL_8453` / `EVM_RPC_URL_84532` / `EVM_RPC_URL`。详见 [在 Base 上付款](./command-reference.md#paying-on-base)。 + +### 可以在不持有 TRX 的情况下付款吗? + +可以,在 TRON 上通过 GasFree 实现。使用 `scheme=exact_gasfree` 时,由一个 relayer 代付网络能量、并从支付代币里扣除手续费,所以付款钱包只需要稳定币、无需 TRX。当接口宣告了该 scheme 时 CLI 会自动选用,也可以用 `--scheme exact_gasfree` 显式要求。由于 relayer 手续费与支付金额分开,用 `--max-gasfree-fee ` 给它封顶。详见 [GasFree 支付](./command-reference.md#gasfree-payments-tron)。 --- @@ -66,7 +79,16 @@ TRON(`tron:mainnet`、`tron:nile`、`tron:shasta`)与 BSC(`eip155:56`、`e | 错误码 | 发生了什么 | 如何修复 | | :--- | :--- | :--- | -| `WALLET_NOT_CONFIGURED` | 找不到付款方私钥 | 设置 `TRON_PRIVATE_KEY` / `EVM_PRIVATE_KEY` / `PRIVATE_KEY`,或配置 agent-wallet 付款钱包 | +| `WALLET_NOT_CONFIGURED` | 该网络没有激活的 Agent Wallet | 设置激活钱包,或用 `--wallet-id` / `AGENT_WALLET_ID` 指定。开发/CI 场景可用 `--private-key` 或 `*_PRIVATE_KEY` 变量 | +| `WALLET_PASSWORD_REQUIRED` | Agent Wallet 需要解锁密码 | 通过 Agent Wallet 支持的安全配置方式提供密码 | +| `WALLET_DECRYPTION_FAILED` | Agent Wallet 密码错误 | 用正确的密码解锁后重试 | +| `WALLET_CONFIG_CORRUPT` | Agent Wallet 配置无法读取 | 检查 `~/.agent-wallet/wallets_config.json`,或重建本地配置 | +| `WALLET_NETWORK_ERROR` | 连不上 Agent Wallet 后端 | 检查到所配置钱包后端的网络连通性 | +| `WALLET_SIGNING_FAILED` | 钱包未能生成签名 | 确认激活钱包支持该网络与本次 typed-data 签名请求 | +| `WALLET_UNSUPPORTED_OPERATION` | 钱包后端不支持该网络的 typed-data 签名 | 换用支持该网络 typed-data 签名的钱包后端 | +| `WALLET_AUTH_FAILED` | 远程钱包认证被拒绝 | 检查远程钱包的认证配置 | +| `WALLET_ERROR` | 其他 Agent Wallet 故障 | 检查激活钱包的配置与后端状态 | +| `TOKEN_TRANSFER_FAILED` | 代币 `transferFrom` 回滚 | 检查代币余额、代币合约,以及付款方的授权额度 | | `TRON_ACCOUNT_NOT_ACTIVATED` | 该 TRON 地址从未在链上使用过 | 先给它转一小笔 TRX 激活,再签名 | | `INSUFFICIENT_TOKEN_BALANCE` | 付款方缺少被收取的代币 | 用服务方宣告的确切代币和网络给付款方充值 | | `INSUFFICIENT_GAS` | 原生 gas / 能量不足 | 给付款方充值该网络的原生 gas 代币(TRX / BNB) | diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/index.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/index.md index ec4f570b..1c609443 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/index.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/index.md @@ -14,10 +14,12 @@ x402 CLI(`@bankofai/x402-cli`)把 [x402 支付协议](../index.md)搬进了 ```bash # 支付任意受 x402 保护的接口 -x402-cli pay https://api.example.com/paid --network tron:nile --token USDT +x402-cli pay https://api.example.com/paid --network tron:0xcd8690dc --token USDT ``` -它完全构建在已发布的 TypeScript SDK 包之上——`@bankofai/x402-core`、`@bankofai/x402-evm`、`@bankofai/x402-tron`——每一笔稳定币支付都使用 `scheme=exact` 配合 Permit2 授权(`extra.assetTransferMethod=permit2`)。 +它完全构建在已发布的 TypeScript SDK 包之上——`@bankofai/x402-core`、`@bankofai/x402-evm`、`@bankofai/x402-fetch`、`@bankofai/x402-tron`。稳定币支付使用 `scheme=exact`:TRON 与 BSC 走 Permit2 授权,Base USDC 走 EIP-3009。TRON 上还支持 `scheme=exact_gasfree`——由 relayer 代付网络能量、并从支付代币里扣除手续费,付款方无需持有 TRX。详见 [GasFree 支付](./command-reference.md#gasfree-payments-tron)。 + +默认情况下,`pay` 使用你当前激活的 [Agent Wallet](../../Agent-Wallet/Intro.md) 签名——不需要把私钥放进环境变量。详见 [用 Agent Wallet 付款](./command-reference.md#paying-with-agent-wallet)。 --- @@ -27,13 +29,13 @@ CLI 把能力归为五条命令。 | 命令 | 作用 | 示例 | | :--- | :--- | :--- | -| **`pay`** | 支付一个受 x402 保护的 URL:探测接口、读取 `402` 支付要求、签名并重试。 | `x402-cli pay --network tron:nile --token USDT` | +| **`pay`** | 支付一个受 x402 保护的 URL:探测接口、读取 `402` 支付要求、签名并重试。 | `x402-cli pay --network tron:0xcd8690dc --token USDT` | | **`serve`** | 启动本地 x402 付费端点,返回 `402 Payment Required` 并通过 Facilitator 结算。 | `x402-cli serve --pay-to
--amount 0.0001` | | **`roundtrip`** | 启动临时服务、立即支付、随后退出——端到端冒烟测试的最快方式。 | `x402-cli roundtrip --pay-to
` | | **`gateway`** | 管理本地网关的 provider 文件:校验、脚手架、启动、构建目录资产。 | `x402-cli gateway check ./providers` | | **`catalog`** | 搜索、缓存、查看、导出托管的服务目录。 | `x402-cli catalog search "weather"` | -只读命令(`pay --dry-run`、`catalog search`、`gateway check`)无需钱包,只有真正发起支付时才需要付款方私钥。 +只读命令(`pay --dry-run`、`catalog search`、`gateway check`)无需钱包。真正发起支付时需要配置可签名的钱包;原始私钥仅作为开发和 CI 的覆盖手段。 --- @@ -42,17 +44,34 @@ CLI 把能力归为五条命令。 输出默认是人类友好的文本。给任意命令加上 `--json`,就能得到一份稳定的、机器可读的结构化 JSON 输出——非常适合脚本和 AI Agent: ```bash -x402-cli pay https://api.example.com/paid --dry-run --json +x402-cli pay 'https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols' \ + --network tron:0x2b6653dc \ + --token USDT \ + --dry-run \ + --json ``` ```json { "ok": true, - "command": "client", - "network": "tron:nile", + "command": "pay", + "component": "client", + "network": "tron:0x2b6653dc", "scheme": "exact", "result": { - "url": "https://api.example.com/paid", + "url": "https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols", + "resource": "https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols", + "selected": { + "scheme": "exact", + "network": "tron:0x2b6653dc", + "amount": "1", + "asset": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", + "payTo": "TLXPgJVJFgL97gc49j8w8kC22mDTpH9EGa", + "maxTimeoutSeconds": 300, + "extra": { + "assetTransferMethod": "permit2" + } + }, "message": "Dry run - no payment submitted" } } @@ -68,23 +87,28 @@ CLI 内置了代币注册表。用 `--network` 指定网络,用 `--token` 指 | 网络 | 标识符 | 内置代币 | | :--- | :--- | :--- | -| **TRON 主网** | `tron:mainnet` | USDT、USDD | -| **TRON Nile 测试网** | `tron:nile` | USDT、USDD | -| **TRON Shasta 测试网** | `tron:shasta` | USDT | +| **TRON 主网** | `tron:0x2b6653dc` | USDT、USDD | +| **TRON Nile 测试网** | `tron:0xcd8690dc` | USDT、USDD | +| **TRON Shasta 测试网** | `tron:0x94a9059e` | USDT | | **BSC 主网** | `eip155:56` | USDT | | **BSC 测试网** | `eip155:97` | USDT、USDC | +| **Base 主网** | `eip155:8453` | USDC | +| **Base Sepolia 测试网** | `eip155:84532` | USDC | -以下简写别名会被自动接受并归一化: +TRON 网络必须使用标准的 CAIP-2 标识符(`tron:0x…`)。旧的别名如 `tron-mainnet`、`tron:nile`、`mainnet` 等**已不再被接受**——CLI 会直接拒绝,并提示应改用的标准标识符。只有 EVM 别名仍会被自动接受并归一化: | 别名 | 标准标识符 | | :--- | :--- | -| `tron-mainnet` | `tron:mainnet` | -| `tron-nile` | `tron:nile` | -| `tron-shasta` | `tron:shasta` | | `bsc-mainnet` | `eip155:56` | | `bsc-testnet` | `eip155:97` | +| `base-mainnet` | `eip155:8453` | +| `base-sepolia` | `eip155:84532` | + +已注册代币的精度以注册表为准,不可覆盖。只有未注册的非 Base 资产,才需要用 `--asset
` 搭配 `--decimals ` 传入。 -如果代币不在注册表里,用 `--asset
` 搭配 `--decimals ` 传入。 +:::note 不同链的授权方式不同 +TRON 与 BSC 的稳定币支付走 **Permit2** 授权,Base USDC 走 **EIP-3009**(`transferWithAuthorization`)。两者都在同一个 `exact` 方案下——CLI 会按网络自动选用,你不需要自己配置。 +::: --- @@ -110,10 +134,11 @@ CLI 内置了代币注册表。用 `--network` 指定网络,用 `--token` 指 :::warning 支付会转移真实的链上资产,且不可撤销。请牢记以下原则: -- **绝不硬编码私钥。** 在共享环境中,优先用环境变量(`TRON_PRIVATE_KEY`、`EVM_PRIVATE_KEY`、`PRIVATE_KEY`)或一个 [agent-wallet](../../Agent-Wallet/Intro.md) 付款钱包,而不是 `--private-key` 参数。 -- **先在测试网上验证。** 上主网前,先用 `tron:nile` 或 `eip155:97` 跑通。 +- **让 Agent Wallet 保管私钥。** 它是默认付款方,并把签名交给配置的钱包后端完成;该后端可以是本地或远程。你不需要把私钥写进 CLI 配置或环境变量。`--private-key` 与 `*_PRIVATE_KEY` 变量仅用于开发和 CI。 +- **先在测试网上验证。** 上主网前,先用 `tron:0xcd8690dc`、`eip155:97` 或 `eip155:84532` 跑通。 - **付款前先预览。** 用 `pay --dry-run` 在签名前看清确切的支付要求。 - **给金额设上限。** 用 `--max-amount` 或 `--max-raw-amount`,让定价异常的接口无法超额扣款。 +- **不要盲目跟随重定向。** CLI 有意不自动跟随付费请求的 HTTP 重定向,以确保 `PAYMENT-SIGNATURE` 不会被转发到其他源。遇到重定向时,先确认目标地址,再显式请求最终 URL。 - **只放最小额度。** 付款方地址里只保留当前任务所需的资金。 ::: diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/quickstart.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/quickstart.md index 3ff244bd..028dc034 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/quickstart.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/cli/quickstart.md @@ -16,7 +16,8 @@ description: >- 1. **Node.js** >= 20([下载](https://nodejs.org/)) 2. **npm**(随 Node.js 一起安装) -3. 用于支付步骤的一个有余额的测试网地址——一个 TRON **Nile** 地址,持有少量测试 **USDT** 和 **TRX**(用于能量)。参见 [钱包](../core-concepts/wallet.md)。 +3. 一个 **[Agent Wallet](../../Agent-Wallet/QuickStart.md)**,并为你要付款的网络设置好激活钱包——CLI 默认用它签名 +4. 用于支付步骤的一个有余额的测试网地址——一个 TRON **Nile** 地址,持有少量测试 **USDT** 和 **TRX**(用于能量)。参见 [钱包](../core-concepts/wallet.md)。 验证你的环境: @@ -48,54 +49,56 @@ x402-cli --help ## 第 2 步:先不花钱试一试 -看到接口真实返回的 `402` 支付要求的最快方式是**空跑(dry run)**。它会探测接口、读取支付要求,并原样打印出你将被要求支付的内容——但不签名、不花钱: +看到接口真实返回的 `402` 支付要求的最快方式是**空跑(dry run)**。它会探测一个真实的 TRON 主网接口、读取支付要求,并原样打印出你将被要求支付的内容——但不签名、不花钱: ```bash -x402-cli pay https://api.example.com/paid \ - --network tron:nile \ +x402-cli pay 'https://x402-gateway.bankofai.io/providers/defillama-tvl-tron/protocols' \ + --network tron:0x2b6653dc \ --token USDT \ --dry-run \ --json ``` -`--dry-run` 的输出包含被选中的支付要求(网络、资产、金额、收款地址)。这就是你的安全网:支付一个陌生接口前,永远先空跑一次。 +这一步读取 TRON 主网支付要求,但 `--dry-run` 不会签名或提交支付。它的输出包含被选中的支付要求(网络、资产、金额、收款地址)。这就是你的安全网:支付一个陌生接口前,永远先空跑一次。 --- ## 第 3 步:在测试网跑一次完整回路 -`roundtrip` 会启动一个临时的本地付费端点、支付它、然后退出——一次完整的端到端测试。你需要一个 Nile 测试网的付款方私钥。 +`roundtrip` 会启动一个临时的本地付费端点、支付它、然后退出——一次完整的端到端测试。签名由你在 Nile 上激活的 Agent Wallet 完成。 ```bash -TRON_PRIVATE_KEY=<你的-nile-十六进制私钥> \ x402-cli roundtrip \ --pay-to <你的-nile-收款地址> \ --amount 0.0001 \ - --network tron:nile \ + --network tron:0xcd8690dc \ --token USDT ``` 成功时,CLI 会打印出已结算的交易。那串交易哈希,就是这笔支付已在链上清算的凭证——恭喜,你的环境端到端跑通了。 :::caution 保管好你的私钥 -私钥请通过环境变量传入(TRON 用 `TRON_PRIVATE_KEY`,EVM 用 `EVM_PRIVATE_KEY`,`PRIVATE_KEY` 是两种网络通用的回退),绝不要在共享 Shell 或提交到版本库的脚本里以明文命令行参数传递——命令行参数可能被本机其它进程看到。任何超出一次性测试范围的场景,请使用 [agent-wallet](../../Agent-Wallet/QuickStart.md) 付款钱包。 +CLI 使用你当前激活的 [Agent Wallet](../../Agent-Wallet/QuickStart.md) 签名,私钥不会进入 Shell 或配置文件。如果配置了钱包但没有激活项,CLI 会在签名前停下——请设置激活钱包,或用 `--wallet-id` 指定。`--private-key` 参数与 `*_PRIVATE_KEY` 变量仅供开发和 CI 使用;共享环境中请优先用环境变量而非命令行参数,后者可能被本机其它进程看到。 ::: --- ## 第 4 步:支付真实的 x402 接口 -回路跑通后,支付任意受 x402 保护的 URL,就是同一条 `pay` 命令指向真实资源: +回路跑通后,支付任意受 x402 保护的 URL 都使用同一条命令。请将下面的占位符替换为 provider 公布的 URL、网络与代币: ```bash -TRON_PRIVATE_KEY=<你的十六进制私钥> \ -x402-cli pay https://api.example.com/paid \ - --network tron:nile \ - --token USDT \ +x402-cli pay '' \ + --network \ + --token \ --max-amount 0.01 ``` -`--max-amount` 给你愿意支付的金额封顶:如果接口价格超过它,CLI 会在签名前中止。EVM 网络请使用 `EVM_PRIVATE_KEY`(或通用回退 `PRIVATE_KEY`)以及像 `eip155:97` 这样的 EVM 网络。 +`--max-amount` 给你愿意支付的金额封顶:如果接口价格超过它,CLI 会在签名前中止。同一条命令在 EVM 网络上同样适用——把 `--network` 指向 `eip155:97`(BSC 测试网)或 `base-sepolia`(Base Sepolia,USDC)即可。 + +:::tip 没有 TRX?用 GasFree +在 TRON 上,如果接口宣告了 `exact_gasfree`,CLI 可以在钱包里没有 TRX 的情况下付款——由一个 relayer 代付网络能量、并从支付代币里扣除手续费。CLI 会自动选用,你也可以用 `--scheme exact_gasfree` 显式要求,并用 `--max-gasfree-fee` 给 relayer 手续费封顶。详见 [GasFree 支付](./command-reference.md#gasfree-payments-tron)。 +::: --- @@ -107,7 +110,7 @@ x402-cli pay https://api.example.com/paid \ x402-cli serve \ --pay-to <你的收款地址> \ --amount 0.0001 \ - --network tron:nile \ + --network tron:0xcd8690dc \ --token USDT \ --port 4020 ``` @@ -122,7 +125,7 @@ x402-cli serve \ 在另一个终端里支付它: ```bash -TRON_PRIVATE_KEY= x402-cli pay http://127.0.0.1:4020/pay --network tron:nile --token USDT +x402-cli pay http://127.0.0.1:4020/pay --network tron:0xcd8690dc --token USDT ``` 用 `--facilitator-url` 指向特定的 Facilitator(默认 `https://facilitator.bankofai.io`),加上 `--daemon` 可让服务在后台运行并打印子进程 id。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/gateway.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/gateway.md index 7faaadb1..e2646083 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/gateway.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/gateway.md @@ -62,7 +62,7 @@ Agent ──► 网关 ──► 你的上游 API ### 面向 API 提供方:上架 API,让每一次调用都产生收入 - **资金直接入账** —— 款项实时结算至收款钱包,无平台托管,无结算周期。 -- **原生多链** —— 可在 TRON 或 BNB Chain 结算,由提供方自主选择。 +- **原生多链** —— 可根据服务商发布的路由在 TRON、BNB Chain 或 Base 主网结算。 - **零改动接入** —— 现有 API 保持原样,无需改动任何代码。 - **定价自主** —— 可按接口、按档位灵活定价,免费接口依然免费。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/network-and-token-support.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/network-and-token-support.md index e3a8d6be..0baa52ab 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/network-and-token-support.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/network-and-token-support.md @@ -29,6 +29,18 @@ x402 采用 CAIP-2 网络标识符格式:`tron:`。 > **注意**:在自托管 Facilitator 的 YAML 配置文件中,使用更易读的格式:`bsc:mainnet` 和 `bsc:testnet`。Facilitator 启动时会自动将其映射为协议层对应的 EIP-155 链 ID。 +## Base 网络标识符 + +Base 在 x402 链路中使用标准 EIP-155 标识符: + +| 网络名称 | 协议标识符 | 说明 | +| :------- | :--------- | :--- | +| **Base Mainnet** | `eip155:8453` | 生产网络;API Catalog 发布该网络路由 | +| **Base Sepolia** | `eip155:84532` | CLI/SDK 测试网络 | + +Base 主网使用官方 USDC,通过 `exact` 方案和 EIP-3009 授权完成支付。付款方在链下签署 `transferWithAuthorization`,无需 Permit2 approve。 + + ## 概览 x402 专为区块链生态设计,实现了原生的链上支付验证与结算功能。协议底层采用安全的签名机制,确保消息授权的安全性与防篡改能力。 @@ -42,10 +54,12 @@ x402 专为区块链生态设计,实现了原生的链上支付验证与结算 | **TRON Shasta** | **Testnet** | **备用测试网**:长期稳定的测试环境。 | | **BSC Mainnet** | **Mainnet** | **生产网络**:用于处理真实价值资产。 | | **BSC Testnet** | **Testnet** | **推荐测试网**:BSC 首选的开发与调试环境。 | +| **Base Mainnet** | **Mainnet** | **生产网络**:使用官方 USDC。 | +| **Base Sepolia** | **Testnet** | CLI/SDK 测试;不在 API Catalog 发布。 | ### 支持的代币 -x402 协议全面支持 **TRC-20/BEP-20** 标准代币,并默认将 **USDT** 和 **USDD** 作为主要结算货币。 +x402 支持 **TRC-20、BEP-20 和 ERC-20** 代币。TRON/BSC 路由使用各自配置的稳定币;Base 使用官方 USDC。 #### 支持的代币列表 @@ -61,10 +75,12 @@ x402 协议全面支持 **TRC-20/BEP-20** 标准代币,并默认将 **USDT** | **USDT** | `eip155:97` | `0x337610d27c682E347C9cD60BD4b3b107C9d34dDd` | | **USDC** | `eip155:97` | `0x64544969ed7EBf5f083679233325356EbE738930` | | **DHLU** | `eip155:97` | `0x375cADdd2cB68cE82e3D9B075D551067a7b4B816` | +| **USDC** | `eip155:8453` | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | +| **USDC** | `eip155:84532` | `0x036CbD53842c5426634e7929541eC2318f3dCF7e` | > **扩展支持**:协议具有高度的可扩展性。通过 TRON 代币注册表(`@bankofai/x402-tron` 的 `registerToken`)或 server 的 `EVM_TOKENS` 配置表,您可以轻松配置并支持任意自定义的 TRC-20/BEP-20 代币。 -> **关于 `exact` 方案的代币选择**:ERC-3009 代币(如 BSC 测试网 **DHLU**)通过 `transferWithAuthorization` 无 gas 结算。普通 ERC-20 代币(如 BSC USDC/USDT、TRON USDT/USDD)通过 Permit2 路径结算——客户端首次付款时自动广播一次性 `approve(Permit2)`。每代币的结算方式由 server `accepts[].price.extra` 中的数据决定:ERC-3009 → `{ name, version }`;普通 ERC-20 → `{ assetTransferMethod: "permit2" }`。 +> **关于 `exact` 方案的代币选择**:EIP-3009 代币(如 Base 官方 USDC、BSC 测试网 DHLU)通过 `transferWithAuthorization` 无 gas 结算。普通 ERC-20 代币(如 BSC USDC/USDT、TRON USDT/USDD)通过 Permit2 路径结算——客户端首次付款时自动广播一次性 `approve(Permit2)`。每种代币的结算方式由 server `accepts[].price.extra` 中的数据决定:EIP-3009 → `{ name, version }`;普通 ERC-20 → `{ assetTransferMethod: "permit2" }`。 #### 安全签名 @@ -80,8 +96,8 @@ x402 采用类型化数据签名来处理所有支付相关的签名授权。 在服务端配置 `HTTP 402` 支付要求时,您需要明确指定以下三个核心参数: -1. **网络 (Network)**:目标网络的唯一标识符(例如 `tron:0xcd8690dc`)。 -2. **资产 (Asset)**:目标 TRC-20/BEP-20 代币的**合约地址**。 +1. **网络 (Network)**:目标网络的唯一标识符(例如 `tron:0xcd8690dc` 或 `eip155:8453`)。 +2. **资产 (Asset)**:目标 TRC-20/BEP-20/ERC-20 代币的**合约地址**。 3. **金额 (Amount)**:基于代币**最小单位**(Raw Amount)的整数值。 > **精度换算示例**: @@ -96,7 +112,7 @@ x402 支持四种支付方案。每种方案按链族实现为 client + server + `exact` 方案支付公布的准确金额,覆盖两种代币转账路径: -- **ERC-3009 `transferWithAuthorization`**:适用于原生支持该标准的代币(如 BSC 测试网 DHLU)。无 gas:无需 `approve`;客户端签署类型化数据授权,facilitator 在链上调用 `transferWithAuthorization`。 +- **EIP-3009 `transferWithAuthorization`**:适用于原生支持该标准的代币(如 Base 官方 USDC、BSC 测试网 DHLU)。无 gas:无需 `approve`;客户端签署类型化数据授权,facilitator 在链上调用 `transferWithAuthorization`。 - **Permit2**:适用于不实现 ERC-3009 的普通 ERC-20/TRC-20 代币(如 BSC USDC/USDT、TRON USDT/USDD)。客户端签署 Permit2 witness,facilitator 通过 `x402ExactPermit2Proxy` 合约结算。需要一次性 `approve(Permit2)`;客户端首次付款时自动广播。 `exact` 方案遵循 **x402 Foundation** 发布的 **v2 链路格式**:标准 v2 客户端可直接向本 SDK 的服务端发起付款请求,本 SDK 客户端也可直接访问任何 v2 兼容的服务端——无需项目特定的转换。转账授权数据位于 `payload.authorization` 中。 @@ -149,18 +165,18 @@ Facilitator 作为协议的中间件,承担以下核心职责: **部署先决条件** -- **节点访问权限**:稳定的 RPC 访问(例如 TronGrid 或公共 BSC 端点)。 -- **Gas 资源储备**:一个持有充足 **TRX/BNB** 的钱包,用于支付结算 gas 费用。 +- **节点访问权限**:稳定的 RPC 访问(例如 TronGrid,或 BSC/Base 的 EVM JSON-RPC 端点)。 +- **Gas 资源储备**:一个持有充足 **TRX/BNB/ETH** 的钱包,用于支付结算 gas 费用。 - **代码部署**:运行 `examples/typescript/facilitator/basic` 示例 facilitator。 > **深入了解**:请查阅 [Facilitator](./facilitator.md) 文档以获取详细的配置指南与 API 参考,以及[卖家快速入门](../getting-started/quickstart-for-sellers.md)。 ### 快速参考 -| 核心组件 | TRON/BSC 实现详情 | +| 核心组件 | TRON/BSC/Base 实现详情 | | :----------- | :----------------------------------------- | -| **网络环境** | `tron:0x2b6653dc`, `tron:0x94a9059e`, `tron:0xcd8690dc`, `eip155:56`, `eip155:97` | -| **代币标准** | TRC-20 代币(默认内置 USDT 和 USDD 支持),BEP-20 代币 | +| **网络环境** | `tron:0x2b6653dc`, `tron:0x94a9059e`, `tron:0xcd8690dc`, `eip155:56`, `eip155:97`, `eip155:8453`, `eip155:84532` | +| **代币标准** | TRC-20 代币(默认内置 USDT 和 USDD 支持)、BEP-20 代币、ERC-20 代币(Base 官方 USDC) | | **签名机制** | TIP-712 / EIP-712 类型化数据签名 | | **支付方案** | `exact`、`upto`、`batch-settlement`、`exact_gasfree`(TRON) | @@ -185,11 +201,11 @@ registerToken(TRON_NILE, { ### 总结 -x402 专为区块链架构深度定制,提供了原生的 TRC-20/BEP-20 代币集成与安全签名支持。 +x402 专为区块链架构深度定制,提供了原生的 TRC-20/BEP-20/ERC-20 代币集成与安全签名支持。 **核心要点:** - **开发环境**:推荐优先使用 **测试网** 进行开发与调试。 -- **原生资产**:**USDT** 为默认的首选结算代币,且 SDK 已预置相关合约地址配置。 +- **默认结算资产**:TRON/BSC 路由使用各自配置的稳定币;Base 使用官方 **USDC**。 - **安全机制**:TIP-712 / EIP-712 类型化数据签名机制确保了安全且最小化信任 (Trust-minimized) 的支付授权流程。 - **扩展能力**:可通过 TRON 代币注册表(`registerToken`)或 server 的 `EVM_TOKENS` 配置表灵活扩展支持任意自定义的 **TRC-20/BEP-20 代币**。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/faq.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/faq.md index a57284b7..911affc0 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/faq.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/faq.md @@ -7,7 +7,7 @@ import TabItem from '@theme/TabItem'; #### 一句话概括 x402 是什么? -x402 唤醒了长期闲置的 HTTP `402 Payment Required` 状态码,将其转化为一个基于区块链的功能完备的链上支付层,专为 API、网站及自主 AI 代理设计。目前,x402 已在 TRON 和 BSC 网络上支持,并计划在未来扩展至多链生态,实现广泛的区块链网络覆盖。 +x402 唤醒了长期闲置的 HTTP `402 Payment Required` 状态码,将其转化为一个基于区块链的功能完备的链上支付层,专为 API、网站及自主 AI 代理设计。目前,x402 已支持 TRON、BSC 和 Base,并计划在未来扩展至更广泛的多链生态。 #### x402 是商业产品吗? @@ -62,7 +62,7 @@ x402 是**仅 TypeScript** 的 SDK,以颗粒化的 `@bankofai/x402-*` 包发 x402 支持四种支付方案: -- **`exact`**:支付公布的准确金额。ERC-3009 代币(如 BSC 测试网 DHLU)通过 `transferWithAuthorization` 无 gas 结算;普通 ERC-20/TRC-20 代币(如 BSC USDC/USDT、TRON USDT/USDD)通过 Permit2 路径结算,首次付款需一次性 `approve(Permit2)`。`exact` 的协议 payload 遵循 **x402 Foundation** 的 v2 规范。 +- **`exact`**:支付公布的准确金额。EIP-3009 代币(如 Base 官方 USDC、BSC 测试网 DHLU)通过 `transferWithAuthorization` 无 gas 结算;普通 ERC-20/TRC-20 代币(如 BSC USDC/USDT、TRON USDT/USDD)通过 Permit2 路径结算,首次付款需一次性 `approve(Permit2)`。`exact` 的协议 payload 遵循 **x402 Foundation** 的 v2 规范。 - **`upto`**:按量计费——客户端签署最高至最大金额的 Permit2 授权,服务端仅结算**实际用量**(≤ max)。非常适合**按量计费**、**LLM Token 消耗**等场景。 - **`batch-settlement`**:面向高频微支付的支付通道——一次性链上存入,然后用链下凭证支付多次请求,一笔交易批量结算。含退款路径。 - **`exact_gasfree`**(仅限 TRON):允许买家使用 USDT/USDD 付款而无需持有 TRX 来支付 gas。由 relayer 通过 GasFree API 支付链上 energy——客户端无需配置 API 密钥。 @@ -75,6 +75,7 @@ x402 支持四种支付方案: - 本 SDK 的客户端可以直接向 v2 兼容的服务端付款。 - V2 结构中转账授权数据位于 `payload.authorization` 字段(结构化对象);作为迁移过渡,客户端还会同时填充 `extensions.transferAuthorization`,以便仍在运行旧版本的服务端也能解析。 - BSC USDT/USDC 是普通 ERC-20(无 ERC-3009),在 `exact` 方案下通过 Permit2 路径结算——客户端首次付款时自动广播一次性 `approve(Permit2)`。ERC-3009 代币(如 BSC 测试网 DHLU)则无 gas 结算,无需 approve。 +- Base 主网官方 USDC 在 `exact` 下使用 EIP-3009:付款方签署 `transferWithAuthorization`,无需 Permit2 approve。 - 仓库中的 `examples/bsc-testnet-smoke/` 目录提供了双向互通的烟雾测试示例(Coinbase 官方客户端 → BANK OF AI 服务端、BANK OF AI 客户端 → Coinbase 官方服务端),可作为调试与集成参考。 ### 资产、网络及费用 @@ -94,6 +95,8 @@ x402 支持四种支付方案: | BSC testnet (`eip155:97`) | USDT (BEP-20) | **Testnet** | | BSC testnet (`eip155:97`) | USDC (BEP-20) | **Testnet** | | BSC testnet (`eip155:97`) | DHLU (BEP-20, 用于 `exact` 互通测试) | **Testnet** | +| Base 主网 (`eip155:8453`) | 官方 USDC(ERC-20,EIP-3009) | **Mainnet** | +| Base Sepolia (`eip155:84532`) | USDC(ERC-20,EIP-3009) | **Testnet** | 此外,可通过 TRON 代币注册表(`@bankofai/x402-tron` 的 `registerToken`)添加自定义 TRC-20 代币;自定义 BEP-20 代币则通过在 server 的 `EVM_TOKENS` 配置表中添加条目来公布。 @@ -102,6 +105,7 @@ x402 支持四种支付方案: - **网络费用**: - 在 TRON 链上用于支付能量 (Energy) 和带宽 (Bandwidth) 消耗的 TRX(由 Facilitator 承担)。 - 在 BSC 链上用于支付 gas 消耗的 BNB(由 Facilitator 承担)。 + - 在 Base 链上用于支付 gas 的 ETH(由 Facilitator 承担)。 - **Facilitator 服务费**:每个 Facilitator 可独立配置的服务费用(支持设置为零)。 ### 安全性 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/getting-started/quickstart-for-sellers.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/getting-started/quickstart-for-sellers.md index 54aa9065..4df5a3ed 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/getting-started/quickstart-for-sellers.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/getting-started/quickstart-for-sellers.md @@ -84,6 +84,22 @@ git --version # 版本控制工具 > ✅ **成功:** 钱包显示测试 BNB 和测试 USDT 余额大于 0 + + + +**创建 Base 钱包(约 3 分钟):** + +1. 安装 [Coinbase Wallet](https://www.coinbase.com/wallet) 或 [MetaMask](https://metamask.io/) +2. 创建专用钱包并妥善保存助记词 +3. 切换到 Base 主网 +4. 复制用于接收 USDC 的 `0x` 钱包地址 + +**为收款钱包充值:** + +向钱包转入少量 Base 主网官方 USDC。资源服务器只公布该地址,不需要钱包私钥。主网支付会使用真实资金。 + +> ✅ **成功:** 钱包已显示 Base 官方 USDC,且收款地址以 `0x` 开头 + @@ -100,24 +116,26 @@ git --version # 版本控制工具 |--------|------|----------| | **TRON 钱包地址** | 以 `T` 开头的钱包地址(您的收款地址) | 从 TronLink 复制 | | **BSC 钱包地址** | 以 `0x` 开头的钱包地址(您的收款地址) | 从 MetaMask 复制 | +| **Base 钱包地址** | 以 `0x` 开头的钱包地址(您的收款地址) | 从 Coinbase Wallet 或 MetaMask 复制 | | **测试 TRX** | TRON 测试网费率代币 | [Nile 水龙头](https://nileex.io/join/getJoinPage) | | **测试 USDT/USDD(TRON)** | TRON 测试支付代币(USDT 和 USDD 均支持) | [Nile 水龙头](https://nileex.io/join/getJoinPage) | | **测试 BNB** | BSC 测试网费率代币 | [BSC 测试网水龙头](https://www.bnbchain.org/en/testnet-faucet) | | **测试 USDT(BSC)** | BSC 测试支付代币 | [BSC 测试网水龙头](https://www.bnbchain.org/en/testnet-faucet) | +| **USDC(Base)** | Base 主网官方结算代币 | 将官方 USDC 跨链或转入 Base 主网 | **测试网 vs. 主网:** - **测试网**:使用免费测试代币,不涉及真实资金,适合开发调试。网络标识:`tron:0xcd8690dc` / `eip155:97` -- **主网**:涉及真实支付,上线时使用。网络标识:`tron:0x2b6653dc` / `eip155:56` +- **主网**:涉及真实支付,上线时使用。网络标识:`tron:0x2b6653dc` / `eip155:56` / Base `eip155:8453` --- ## 第一步:安装 SDK 包 -在您的 TypeScript API 项目中安装 Express 适配器和 TRON 支付 scheme: +在您的 TypeScript API 项目中安装 Express 适配器以及 TRON/EVM 支付 scheme: ```bash -pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron +pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron @bankofai/x402-evm ``` 请根据服务框架选择对应包(`@bankofai/x402-express`、`@bankofai/x402-hono`、`@bankofai/x402-fastify` 或 `@bankofai/x402-next`)。如果项目不使用 pnpm,也可以用 `npm install` 或 `yarn add` 安装同名包。 @@ -133,7 +151,7 @@ pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron | 配置 | 说明 | 示例 | |------|------|------| | `HTTPFacilitatorClient.url` | 付款验证与结算服务地址 | `https://facilitator.example.com` | -| `payTo` | 您的 TRON 收款地址 | `T...` | +| `payTo` | 所选网络上的收款地址 | TRON:`T...`;BSC/Base:`0x...` | > 💡 **无密钥 server:** 资源服务器从不签名、不持有私钥——它只公布您的公开收款地址(`payTo`)。签名与结算发生在 client 和 facilitator 侧。 @@ -143,7 +161,10 @@ pnpm add express @bankofai/x402-core @bankofai/x402-express @bankofai/x402-tron ## 第三步:创建付费 API 服务器 -下面是一个最小 Express 资源服务器:`GET /credit` 需要先支付 `1 USDT`,付款成功后返回信用额度数据。 +下面分别给出 TRON 和 Base 的最小 Express 资源服务器。`GET /credit` 需要先完成支付,成功后返回信用额度数据。 + + + ```typescript import express from "express"; @@ -190,13 +211,63 @@ express() .listen(4021); ``` + + + +```typescript +import express from "express"; +import { createResourceServer } from "@bankofai/x402-core"; +import { HTTPFacilitatorClient } from "@bankofai/x402-core/server"; +import { + x402HTTPResourceServer, + paymentMiddlewareFromHTTPServer, +} from "@bankofai/x402-express"; +import { ExactEvmScheme } from "@bankofai/x402-evm/exact/server"; + +const server = createResourceServer( + new HTTPFacilitatorClient({ + url: "https://facilitator.example.com", + }) +); + +server.register("eip155:8453", new ExactEvmScheme()); + +express() + .use( + paymentMiddlewareFromHTTPServer( + new x402HTTPResourceServer(server, { + "GET /credit": { + accepts: [ + { + scheme: "exact", + network: "eip155:8453", + payTo: "0x...", + price: "1 USDC", + }, + ], + }, + }) + ) + ) + .get("/credit", (_req, res) => + res.json({ + status: "success", + credit: 1000000, + }) + ) + .listen(4021); +``` + + + + **关键配置参数:** | 参数 | 说明 | 示例 | |------|------|--------| -| `payTo` | 您的收款钱包地址 | `T...` | -| `accepts[].price` | 每次请求价格 | `"1 USDT"` | -| `accepts[].network` | 使用的网络 | 测试网:`TRON_NILE`(`tron:0xcd8690dc`) | +| `payTo` | 您的收款钱包地址 | TRON:`T...`;Base:`0x...` | +| `accepts[].price` | 每次请求价格 | TRON:`"1 USDT"`;Base:`"1 USDC"` | +| `accepts[].network` | 使用的网络 | TRON Nile:`tron:0xcd8690dc`;Base 主网:`eip155:8453` | | `accepts[].scheme` | 付款方式 | `"exact"` | | `routes` | `"METHOD /path"` → `{ accepts }` 的映射 | `"GET /credit"` | diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/index.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/index.md index 87b71dfd..4f47123f 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/index.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/index.md @@ -7,7 +7,7 @@ description: >- # 欢迎使用 x402 -x402 是一种基于 HTTP `402 Payment Required` 状态码的区块链开放支付标准。它允许 Web 服务通过“先付费后响应”的机制直接对 API 或内容进行收费,无需依赖传统的账户或会话体系。目前,x402 已在 **TRON** 和 **BSC** 网络上支持,并计划在未来扩展至多链生态,实现广泛的区块链网络覆盖。 +x402 是一种基于 HTTP `402 Payment Required` 状态码的区块链开放支付标准。它允许 Web 服务通过“先付费后响应”的机制直接对 API 或内容进行收费,无需依赖传统的账户或会话体系。目前,x402 已支持 **TRON**、**BNB Smart Chain(BSC)** 和 **Base**,并计划在未来扩展至更广泛的多链生态。 **有意参与文档共建?** 欢迎在 [GitHub 仓库](https://github.com/BofAI/docs)提交 PR!我们唯一的原则是保持文档的中立性:除必要的资源链接外,请避免包含任何品牌推广内容。 @@ -66,6 +66,9 @@ x402 目前支持以下网络环境: - **TRON Nile 测试网** (`tron:0xcd8690dc`) - **BSC 主网** (`eip155:56`) - **BSC 测试网** (`eip155:97`) +- **Base 主网**(`eip155:8453`) + +Base 主网使用官方 USDC,通过 `exact` 方案和 EIP-3009 授权完成支付。 > **SDK(仅 TypeScript)**:x402 是仅 TypeScript 的 SDK,以颗粒化 `@bankofai/x402-*` npm 包发布(`core`、`evm`、`tron`、`fetch`、`express`、`hono`、`fastify`、`next`、`axios`、`mcp`、`extensions`)。源码由 pnpm/turbo monorepo 维护,但应用开发应安装已发布的包。支持的方案:`exact`(ERC-3009 / Permit2)、`upto`、`batch-settlement`、`exact_gasfree`(TRON)。此前的 Python + TypeScript SDK 已移至 `legacy/` 仅供参考。完整对比详见 [SDK 功能特性](./sdk-features.md)。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/sdk-features.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/sdk-features.md index aae05d4f..bb55776b 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/sdk-features.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/sdk-features.md @@ -55,8 +55,10 @@ description: 'x402 TypeScript SDK 的功能支持矩阵,以颗粒化 @bankofai | `tron:0x94a9059e` | `TRON_SHASTA` | ✅ | | `eip155:56`(BSC 主网) | - | ✅ | | `eip155:97`(BSC 测试网) | - | ✅ | +| `eip155:8453`(Base 主网) | - | ✅ | +| `eip155:84532`(Base Sepolia) | - | ✅(CLI/SDK 测试) | -> 上游 EVM 链(Base、Base Sepolia、MegaETH、Monad、Hyperliquid)也已接入 EVM 默认资产注册表。在示例中添加一条链仅需编辑配置表——无需改动 SDK。 +> 其他上游 EVM 链(MegaETH、Monad、Hyperliquid)也已接入 EVM 默认资产注册表。公开 API Catalog 只发布 Base 主网路由;Base Sepolia 保留用于 CLI/SDK 测试。 --- @@ -142,6 +144,7 @@ x402 支持四种付款方案。每种方案按链族实现为 client + server + | USDC(BEP-20) | `eip155:56`、`eip155:97` | ✅ | | EPS(BEP-20) | `eip155:56` | ✅ | | DHLU(BSC 测试网,ERC-3009) | `eip155:97` | ✅ | +| 官方 USDC(ERC-20,EIP-3009) | `eip155:8453`、`eip155:84532` | ✅ | | 自定义 TRC-20 / BEP-20 | 任意 | ✅(通过代币注册表 / `EVM_TOKENS` 配置) | --- diff --git a/package.json b/package.json index 27824c14..b29ac354 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@x402-tron/docs", - "version": "1.3.15", + "version": "1.3.16", "description": "x402-tron documentation", "license": "MIT", "resolutions": {