x402 Payment Skill
Invoke x402-enabled AI agent endpoints with automatic token payments on both TRON (TRC20) and EVM-compatible (ERC20) chains.
Overview
The
skill enables agents to interact with paid API endpoints. When an agent receives a
response, this skill handles the negotiation, signing, and execution of the payment using the
tool.
Prerequisites
- Wallet Configuration (agent-wallet):
- Local mode (recommended): set (required), (optional).
- Static mode (env): set exactly one of / .
- 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).
- TronGrid API Key (optional): is optional. Recommended on Mainnet to reduce rate-limit issues.
- GasFree (optional): and are only needed when using GasFree-related commands/flows. When configured, the tool will prefer the scheme over . GasFree also requires an account that is activated with sufficient token balance in the GasFree wallet.
- Dependencies: Run in the directory before first use.
- , , and can also be set in .
Usage Instructions
1. Verification
Before making payments, verify your wallet status:
bash
npx tsx x402-payment/src/x402_invoke.ts --check
2. Invoking an Agent (v2)
Most modern x402 agents use the v2 "invoke" pattern:
bash
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.
bash
npx tsx x402-payment/src/x402_invoke.ts --url https://api.example.com/.well-known/agent.json
- List Entrypoints: List available functions.
bash
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.
bash
# 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
Requires:
,
. Without
, requires a configured TRON wallet from agent-wallet. Returns JSON with
,
,
,
, and per-token
(balance, fees).
5. GasFree Account Activation
Activate a GasFree account that has not been activated yet. Use
first to check activation status.
Defaults: network=
nile, token=
USDT.
bash
# 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 token
from 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
,
,
,
,
, and final
status.
6. Cross-Chain Support
- TRON (TRC20): Use (testnet) or .
- BSC (ERC20): Use (testnet) or (mainnet).
Supported Networks & Tokens
| Chain | Network Name | Common Tokens | USDT Contract |
|---|
| TRON | | USDT, USDD | TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
|
| TRON | | USDT, USDD | TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf
|
| BSC | | USDT, USDC | 0x55d398326f99059fF775485246999027B3197955
|
| BSC | | 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 --check
to 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., ).
- The tool returns JSON with , , and .
- 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
to include full error stack traces in the JSON output when troubleshooting failures.
Last Updated: 2026-03-11