Skip to main content

x402-cli

The BankofAI command-line client for the x402 protocol — pay any x402-protected URL, run your own paywall, or test the full handshake locally. No code required.

x402-cli is the single user-facing entrypoint. It includes payment commands, public catalog discovery, and provider gateway operations under one command tree. The gateway runtime is packaged underneath the CLI, so most users only install and remember x402-cli.

Community copy-paste examples live in examples/README.md.

1. Install

pip install bankofai-x402-cli==0.6.1
x402-cli --version

2. Set up a wallet (one-time)

x402-cli delegates all signing to bankofai-agent-wallet. Configure any supported wallet backend before paying.

agent-wallet list
agent-wallet resolve-address payer

A single key derives both an EVM address and a TRON address. You don't need a separate wallet per chain.

Setup paths (encrypted local store, mnemonic, raw secret, Privy-managed): see agent-wallet — Getting Started. Keep wallet secrets outside this repository.

3. What each command does

Command Who you are What it does
x402-cli pay <url> The payer Hits a URL, and if the server returns 402 Payment Required, the cli signs + submits the payment + retrieves the response.
x402-cli serve The recipient Starts a local 402 paywall endpoint that only returns content after a valid payment is settled.
x402-cli roundtrip Self-test / one-shot transfer Spins up a serve in the background, runs pay against it, and tears it down. The fastest way to make a payment from the command line — and the easiest way to verify your install end-to-end.
x402-cli catalog search <query> API consumer / agent runtime Searches the public x402 catalog to find a matching paid capability before calling it.
x402-cli gateway start ... API provider Starts a self-hosted provider gateway from local provider.yml files.
x402-cli catalog export-gateway <url> --provider <fqn> API provider Exports public catalog.json and pay.md files from a self-hosted gateway for PR submission.

Catalog search can read the hosted catalog, a local dist/catalog.json, or a gateway-exported catalog URL. This is the discovery step for agents and local tooling: the user asks for a capability, the catalog search finds matching paid APIs, then the normal x402 payment client can call the selected gateway URL.

export X402_CATALOG=https://x402-catelog.bankofai.io/api/catalog.json
x402-cli catalog update
x402-cli catalog search "token launch"
x402-cli catalog show sunpump-token-launch
x402-cli catalog endpoints sunpump-token-launch
x402-cli catalog pay-json sunpump-token-launch

For local gateway development:

x402-cli gateway scaffold sunpump-token-launch-tron \
  --output-dir providers/sunpump-token-launch-tron \
  --forward-url https://api.example.com

x402-cli gateway check providers/sunpump-token-launch-tron/provider.yml
x402-cli gateway start --providers-dir providers --host 0.0.0.0 --port 4020

Expected flow with the gateway:

Natural-language intent
  -> x402-cli catalog search
  -> x402-cli catalog show/endpoints/pay-json
  -> provider endpoint from the catalog
  -> x402-cli pay <gateway endpoint>
  -> x402 SDK handles the 402 challenge and payment retry
  -> upstream API result

Provider onboarding flow:

x402-cli gateway check providers/sunpump-token-launch-tron/provider.yml
x402-cli gateway start --providers-dir providers --host 0.0.0.0 --port 4020

x402-cli catalog export-gateway https://x402-gateway.bankofai.io \
  --provider sunpump-token-launch-tron \
  --output-dir providers/sunpump-token-launch-tron

The command writes public PR files only:

providers/sunpump-token-launch/catalog.json
providers/sunpump-token-launch/pay.md

Do not submit provider.yml, .env, upstream API keys, bearer tokens, or passwords.

Provider catalog build commands are also under x402-cli:

x402-cli gateway catalog generate providers/sunpump-token-launch-tron/provider.yml
x402-cli gateway catalog pay-assets providers/sunpump-token-launch-tron/provider.yml
x402-cli gateway catalog check providers
x402-cli gateway catalog build providers --dist-dir dist
x402-cli gateway catalog search providers sunpump

4. Copy-paste: a USDT transfer on TRON mainnet

Replace <recipient-TRON-address> with a real T... address and run:

x402-cli roundtrip \
  --pay-to <recipient-TRON-address> \
  --amount 1 \
  --token USDT \
  --network tron:mainnet

Successful output (excerpt):

{
  "ok": true,
  "result": {
    "scheme": "exact_permit",
    "amount": "1000000",
    "paid": true,
    "transaction": "<64-hex-tx-hash>"
  }
}

Verify on chain at https://tronscan.org/#/transaction/<tx-hash>.

What just happened? Your wallet signed a permit off-chain (free, no gas), and the facilitator submitted it on chain on your behalf. You pay no TRX per payment — the facilitator covers gas.

First-time only: if this is your wallet's first payment for this token, the cli will ask you to sign and broadcast a one-time approve transaction (~6 TRX on mainnet) so the PaymentPermit contract can move tokens on your behalf later. After that, every payment is gas-free from your side.

Don't have any TRX at all? Add --scheme exact_gasfree to skip even that one-time approve — it routes everything through a GasFree relayer that fronts gas in exchange for a per-settlement fee deducted from a derived custodial address.

Templates for other networks

Network Replace --network with Notes
TRON mainnet (default permit) tron:mainnet Facilitator pays per-payment gas. One-time ~6 TRX approve when you first use a token from a fresh wallet. Add --scheme exact_gasfree to skip that too.
BSC mainnet (USDT permit) eip155:56 Same model — facilitator pays per-payment gas; one-time approve fee in BNB on first use.

To force a specific settlement scheme (instead of the auto-pick), add --scheme exact_gasfree | exact_permit | exact.

5. Amount units

rawAmount = amount × 10^decimals
What you mean Flag to use
"1.25 USDT" (human-readable decimal) --amount 1.25
1250000 (smallest on-chain unit, USDT has 6 decimals) --rawAmount 1250000

Spending caps on pay follow the same split: --max-amount / --max-rawAmount.

6. Common errors

Error Resolution
Insufficient GasFree balance The GasFree custodial address is underfunded. See top-up steps.
cannot import name 'TokenRegistry' … You're on bankofai-x402-cli ≤ 0.1.0b10. Upgrade: pip install --pre --upgrade bankofai-x402-cli.
resolve_wallet could not find a wallet source No wallet configured yet. Go back to step 2.
Stuck on Master Password: prompt A local_secure wallet without a persisted runtime password. Re-run with --save-runtime-secrets.
too many pending transfers GasFree relayer rate limit. Wait 30–60s and retry.

Full troubleshooting matrix: docs/manual-test-guide.md → Troubleshooting.

Learn more

  • docs/manual-test-guide.md — full hands-on walkthroughs from install to on-chain tx, covering TRON GasFree, TRON permit, and BSC permit.
  • FEATURES.md — full flag matrix and example output for each command.
  • agent-wallet docs — wallet setup options (Privy, mnemonic, encrypted local store).
  • bankofai-x402 SDK — the underlying protocol and its programmatic API, in case you want to integrate directly instead of through the cli.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bankofai_x402_cli-0.6.1.tar.gz (228.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bankofai_x402_cli-0.6.1-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file bankofai_x402_cli-0.6.1.tar.gz.

File metadata

  • Download URL: bankofai_x402_cli-0.6.1.tar.gz
  • Upload date:
  • Size: 228.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bankofai_x402_cli-0.6.1.tar.gz
Algorithm Hash digest
SHA256 4bbf00ad406ba76285b9cbe7a08678399b614a27f82e15d100c68dfcfa117a02
MD5 ba823ca1a8ef5ec856187b33101e4dd7
BLAKE2b-256 8409be53b61a5e4bcd1d9f26927206b5a2f7aa972d98eb86120625319dcbd063

See more details on using hashes here.

File details

Details for the file bankofai_x402_cli-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bankofai_x402_cli-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9570046a990578d376fc64ef81a7ce525f7f6d2a5361559ba29942d7b4c60c5e
MD5 9be1fbd9cb0d36da87721db97b7dc974
BLAKE2b-256 ffa0a8c81a68feba47be85e7eeed836e3b602bf4a73f223f780a0c0a381e8b10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page