x402-payment
x402 Payment Skill
Invoke x402-enabled AI agent endpoints with automatic token payments on both TRON (TRC20) and EVM-compatible (ERC20) chains.
Overview
The x402-payment skill enables agents to interact with paid API endpoints. When an agent receives a 402 Payment Required response, this skill handles the negotiation, signing, and execution of the payment using the x402_invoke tool.
This release is aligned with @bankofai/x402@0.5.9, including Exact V2-compatible payload generation for EVM and TRON.
Prerequisites
Wallet required: Run
agent-wallet listfirst.
If no wallets exist, invokebankofai-guide(Section C — Wallet Guard) before proceeding.
- Wallet Configuration (agent-wallet):
- Local mode (recommended): set
AGENT_WALLET_PASSWORD(required),AGENT_WALLET_DIR(optional). - Static mode (env): set exactly one of
AGENT_WALLET_PRIVATE_KEY/AGENT_WALLET_MNEMONIC. - Optional for mnemonic mode:
AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX. - Configure a TRON wallet for TRC20 payments (USDT/USDD) and/or an EVM wallet for ERC20 payments (USDT/USDC).
- Local mode (recommended): set
- Signing Model: This skill resolves signers through
agent-wallet. It does not scan raw private keys from generic config files or unrelated MCP server configs. - TronGrid API Key (optional):
TRON_GRID_API_KEYis optional. Recommended on Mainnet to reduce rate-limit issues. - GasFree (optional): GasFree credentials are now managed internally by the
@bankofai/x402library. The tool will prefer theexact_gasfreescheme overexact_permit. GasFree requires an account that is activated with sufficient token balance in the GasFree wallet. - Node.js: Use Node 20+ to match the minimum runtime required by
@bankofai/x402@0.5.9. - Dependencies: Run
npm installin thex402-payment/directory before first use. TRON_GRID_API_KEYcan also be set inx402-config.json.
Usage Instructions
1. Verification
Before making payments, verify your wallet status:
npx tsx x402-payment/src/x402_invoke.ts --check
2. Invoking an Agent (v2)
Most modern x402 agents use the v2 "invoke" pattern:
npx tsx x402-payment/src/x402_invoke.ts \
--url https://api.example.com \
--entrypoint chat \
--input '{"prompt": "Your query here"}' \
--network nile
3. Agent Discovery (Direct)
- Manifest: Fetch agent metadata.
npx tsx x402-payment/src/x402_invoke.ts --url https://api.example.com/.well-known/agent.json - List Entrypoints: List available functions.
npx tsx x402-payment/src/x402_invoke.ts --url https://api.example.com/entrypoints
4. GasFree Wallet Info
Query GasFree wallet information (address, activation status, balance, nonce). Defaults: network=mainnet, wallet=agent-wallet active TRON wallet.
# Default: mainnet + active TRON wallet
npx tsx x402-payment/src/x402_invoke.ts --gasfree-info
# Specify wallet address
npx tsx x402-payment/src/x402_invoke.ts --gasfree-info --wallet <YOUR_WALLET_ADDRESS>
# Specify network
npx tsx x402-payment/src/x402_invoke.ts --gasfree-info --network nile
# Both
npx tsx x402-payment/src/x402_invoke.ts --gasfree-info --wallet <YOUR_WALLET_ADDRESS> --network nile
Without --wallet, requires a configured TRON wallet from agent-wallet. Returns JSON with gasFreeAddress, active, allowSubmit, nonce, and per-token assets (balance, fees).
5. GasFree Account Activation
Activate a GasFree account that has not been activated yet. Use --gasfree-info first to check activation status.
Defaults: network=nile, token=USDT.
# Default: nile + USDT
npx tsx x402-payment/src/x402_invoke.ts --gasfree-activate
# Specify network
npx tsx x402-payment/src/x402_invoke.ts --gasfree-activate --network mainnet
# Specify network and token
npx tsx x402-payment/src/x402_invoke.ts --gasfree-activate --network nile --token USDT
Requires: TRON wallet configured in agent-wallet. Wallet must have enough tokens to cover activation fees (~3.05 USDT on nile). If the account is already activated, returns {"status": "already_active"} immediately.
Activation process:
- Queries GasFree account info and checks activation status
- Transfers
activateFee + transferFee + 1 tokenfrom wallet to gasFreeAddress (on-chain TRC20) - Polls for on-chain confirmation (up to 60s)
- Submits a GasFree signed transaction to transfer tokens back to wallet (triggers activation)
- Polls until the GasFree transaction completes
Returns JSON with status, depositTxId, gasFreeTraceId, gasFreeState, gasFreeTxHash, and final active status.
6. Cross-Chain Support
- TRON (TRC20): Use
--network nile(testnet) ormainnet. - BSC (ERC20): Use
--network bsc-testnet(testnet) orbsc(mainnet).
Supported Networks & Tokens
| Chain | Network Name | Common Tokens | USDT Contract |
|---|---|---|---|
| TRON | mainnet |
USDT, USDD | TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t |
| TRON | nile |
USDT, USDD | TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf |
| BSC | bsc |
USDT, USDC | 0x55d398326f99059fF775485246999027B3197955 |
| BSC | bsc-testnet |
USDT, USDC, DHLU | 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd |
Security Considerations & Rules
[!CAUTION] Wallet Secret Safety: NEVER output wallet private keys or mnemonic phrases to logs or console. Use agent-wallet managed configuration.
Agent Security Rules:
- No Private Key Output: The Agent MUST NOT print, echo, or output any private key to the dialogue context.
- No Mnemonic Output: The Agent MUST NOT print or expose mnemonic phrases.
- Internal Loading Only: Rely on the tool to load wallet credentials internally via agent-wallet.
- No Export Commands: DO NOT execute shell commands containing the private key as a literal string.
- Silent Environment Checks: Use
[[ -n $AGENT_WALLET_PASSWORD ]] && echo "Configured" || echo "Missing"to verify local mode configuration without leaking secrets. - Use the Check Tool: Use
npx tsx x402-payment/src/x402_invoke.ts --checkto safely verify addresses.
Binary and Image Handling
If the endpoint returns an image or binary data:
- The data is saved to a temporary file (e.g.,
/tmp/x402_image_...). - The tool returns JSON with
file_path,content_type, andbytes. - Important: The Agent is responsible for deleting the temporary file after use.
Error Handling
Insufficient Allowance
If allowance is insufficient, the tool will automatically attempt an "infinite approval" transaction. Ensure you have native tokens (TRX or BNB/ETH) for gas.
Insufficient Balance
Ensure you have enough USDT/USDC/USDD in your wallet on the specified network.
Debug Stack Trace
Set X402_DEBUG=1 to include full error stack traces in the JSON output when troubleshooting failures.
More from bofai/skills
recharge-skill
BANK OF AI account query and recharge skill. Use for requests like 'recharge 1 usdt', '给 BANK OF AI 充值 1 USDT', or to query BANK OF AI balance/orders. Recharge uses the remote MCP endpoint https://recharge.bankofai.io/mcp with the single `recharge` tool.
81tronscan data lookup
Query TRON blockchain data via the TronScan API — accounts, transactions, tokens, blocks, contracts, transfers, and chain statistics.
79sunswap dex trading
Execute token swaps, manage liquidity, and query market data on SunSwap DEX via the sun-cli.
77sunperp perpetual futures trading
Trade USDT-margined perpetual futures on SunPerp (TRON) — place orders, manage positions, query market data, and manage account via REST API.
76multi-sig & account permissions
Manage TRON multi-sig permissions — configure keys, thresholds, and co-signed proposals.
73trc20 token toolkit
Universal TRC20 token operations — transfer, approve, query balances, and fetch metadata.
68