x402
Monetize any user project/service with the x402 payment protocol on platform networks (Base + Monad + Robinhood + X Layer + Solana; Starchild platform billing: pay_per_use / lifetime / weekly / monthly / quarterly / yearly / prepaid, plus multi-plan services), limited-time free promotions (amount-0
By starchild-ai-agent · 1,135 installs
npx skills add starchild-ai-agent/official-skills --skill x402
Source repository · Upstream listing
💸 x402 Monetization Skill
Turn any local HTTP service into a paid service on platform networks (Base +
Monad + Robinhood + X Layer; x402 V2 protocol, exact scheme, USDC/USDG via EIP 3009 —
buyer pays zero gas), and act as a buyer paying other agents' x402 services
with the user's Privy wallet.
Architecture: reverse proxy sidecar. The gateway ( gateway/app.py ) sits in
front of the user's untouched service. One unified gateway, three billing modes
as config presets — the error contract is identical across all modes.
Reference files (MUST read before the matching task)
Detailed material lives in skills/x402/references/ — it is part of this
skill. Do NOT guess or improvise what these files cover:
Before you… MUST first read file
deploy ANY selling mode beyond basic pay per use (full commands, prepaid & multi plan contracts, admin tokens, templates, gateway lifecycle, always on/update mode) skills/x402/references/selling.md
enable / debug / explain limited time free promotion (amount=0, no settle, P1–P5 ACL, buyer free flow, resource isolation, verify matrix) skills/x402/references/selling.md → Limited time free promotion
free promo errors (still charged, upstream 401, amount not 0, wrong service unlocked) skills/x402/references/troubleshooting.md → Limited time free promotion
debug ANY other error (facilitator verify errors, error contract, security model, port ownership, proxy) skills/x402/references/troubleshooting.md
use the session EOA signer, fund a buyer wallet, or pay on a non Base USDC chain/token skills/x402/references/buying advanced.md
Limited time free promotion (seller quick rules)
For a listed paid marketplace service the owner can open a free window
(max 90 days). Full playbook: references/selling.md → Limited time free promotion .
Agent MUST:
1. Not blind PUT free promo from a UI prompt — run P1–P5 self check first.
2. Remember free = wallet identity + amount 0 verify + no settle/debit , not anonymous
and not a free lifetime subscription after the window.
3. On platform gateway : amount 0 challenge and skip settle/debit are built in.
4. On custom upstream keys (P3/P4) or self built x402 : you MUST patch ACL /
force amount="0" / skip settle — see selling.md Step C.
5. Use x402 resource (path) for access isolation — never invent service id on the wire.
6. After enable: verify free status, 402 amount=0, free call without settlement, then
confirm paid path returns after cancel/expiry.
Buyer tip: if unpaid 402 shows accepts[].amount == "0" , sign 0 (no USDC needed);
do not force list price signing during free.
Sell — monetize a service (quick start)
Platform modes follow the community gateway billing contract: 402 JSON body
with accepts as a list (multi accepts, one entry per network — the buyer
picks one chain per payment), accepts[].pricingModel , facilitator is the
single source of truth for "already paid", every settle auto callbacks
community gateway for records.
Billing mode decision table
Mode Tier Buyer UX When
pay per use platform X PAYMENT each request, settled every call simple data endpoints, agent to agent one shots
lifetime platform pay once, permanent access (facilitator verified) one time unlock, buyout pricing
monthly platform pay once per natural month SaaS style subscriptions
weekly / quarterly / yearly platform fixed length pass: 7 / 90 / 365 days from newest payment short trials, annual discounts
prepaid platform one on chain deposit → off chain debit per call high frequency / sub cent / usage metered APIs
payperuse legacy SDK V2 headers, pay per request pre 2.0 deployments
subscription extended x402 top up → API key + N credits, 1 credit/call prepaid credits, avoids per call payment latency
metered extended like subscription, route weighted units mixed cheap/expensive endpoints (LLM calls etc.)
timepass extended x402 payment → N day pass on an API key fixed duration passes (non natural month)
⚠️ lifetime/monthly/weekly/quarterly/yearly REQUIRE facilitator admin token
(fail closed at startup). Multi plan: plan MODE=PRICE (repeatable).
→ MUST read references/selling.md BEFORE deploying any of these modes —
it has the exact commands, contract details, and template list.
Output includes gateway port . Expose the GATEWAY port, not the upstream
(via preview or community publish). pay to defaults to the user's Privy
EVM wallet — revenue lands there directly.
Registry: /data/workspace/.x402/services.json ; per service config/log/state:
/data/workspace/.x402/<name / .
Networks & facilitators
The platform supports multiple chains. By default a service follows the
platform mainnet full set ( networks all , the default) — currently
Base + Monad + Robinhood + X Layer + Solana. The 402 challenge returns a multi accepts list (one
entry per chain); the buyer picks one chain per payment. Lock to specific
chains with networks eip155:8453,eip155:143,eip155:4663,eip155:196 (custom).
Network CAIP 2 Stablecoin EIP 712 name Gas
Base mainnet eip155:8453 USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 USD Coin ETH (platform paid)
Base Sepolia (testnet) eip155:84532 USDC 0x036CbD53842c5426634e7929541eC2318f3dCF7e USDC ETH (platform paid)
Monad mainnet eip155:143 USDC 0x754704bc059f8c67012fed69bc8a327a5aafb603 USDC MON (platform paid)
Monad testnet eip155:10143 USDC 0x534b2f3A21130d7a60830c2Df862319e593943A3 USDC MON (platform paid)
Robinhood mainnet eip155:4663 USDG 0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168 Global Dollar ETH (platform paid)
Robinhood testnet eip155:46630 USDG 0x7E955252E15c84f5768B83c41a71F9eba181802F Global Dollar ETH (platform paid)
X Layer mainnet eip155:196 USDC 0x74b7F16337b8972027F6196A17a631aC6dE26d22 USD Coin OKB (platform paid)
X Layer testnet eip155:1952 USDC 0x74b7F16337b8972027F6196A17a631aC6dE26d22 USD Coin OKB (platform paid)
Facilitator Networks When
platform ( https://starchild x402 facilitator.fly.dev , the default for mainnet; override via X402 FACILITATOR URL or facilitator ) Base + Monad + Robinhood + X Layer + Solana mainnet production — platform settler pays gas on every chain
https://x402.org/facilitator (default for testnet) Base Sepolia + Monad + Robinhood + X Layer testnet testing only — REJECTED for mainnet (startup guard)
The platform facilitator handles /verify + /settle on every supported chain;
its settler key only pays gas — fund flow is fixed by the buyer's signature and
can never touch user funds. Gas/fees are paid by the platform on every chain
(ETH on Base, MON on Monad, ETH on Robinhood, OKB on X Layer, SOL on Solana) — never passed to the service
provider. Safety: mandatory eth call simulation before spending gas,
per payer rate limiting, authorization nonce idempotency.
Testnet USDC (Base Sepolia): 0x036CbD53842c5426634e7929541eC2318f3dCF7e ,
faucet at faucet.circle.com. Prices auto convert: $0.01 → 10000 atomic USDC units.
Multi chain config ( networks mode )
Config Behavior
networks all (default) or networks mode: all 402 accepts = platform mainnet full set (Base + Monad + Robinhood + X Layer + Solana); testnet full set when facilitator is x402.org
networks eip155:8453 or networks mode: custom + networks: [...] 402 accepts = exactly the listed chains (custom lock)
(no networks field) same as all
Extending the platform with a new chain only requires updating ASSETS +
MAINNET NETWORKS in platform modes.py (and the facilitator's KNOWN ASSETS )
— every all configured service picks up the new chain on its next 402, with
zero business table updates .
⚠️ Robinhood USDG note : the USDG contract uses a Diamond proxy with a
non standard EIP 712 domain. The facilitator reads DOMAIN SEPARATOR() from
chain for verification. Buyer side raw digest signing is a TODO (see
client.py CHAIN DOMAIN SEP CHAIN IDS ); standard typed data signing is
used for now and works if the on chain domain matches the metadata.
Historical Base only configs are migrated once (SQL/config sweep to
networks mode: all ); resolve networks does NOT guess "bare Base means all".
Keepalive (register once per machine)
One watchdog guards ALL x402 gateways (cloudflare skill pattern: idempotent,
prints only on state change → silent scheduled task when healthy):
1. Boot: append to /data/workspace/setup.sh :
bash /data/workspace/skills/x402/scripts/keepalive.sh true
2. Watchdog: scheduled task(action="schedule", schedule="every 10 minutes", command="bash skills/x402/scripts/keepalive.sh", deliver="origin") — empty output = silent.
⚠️ Use the RELATIVE path ( skills/x402/... ), never /data/workspace/skills/... — the
scheduler's path sanitizer strips workspace/ from absolute commands, mangling them
into a nonexistent /data/skills/... and the task fails every run. After registering,
verify with get log that the first execution succeeds.
Gateway down → restarted from its config. Upstream down → reported but NOT
restarted (upstream has its own supervisor via previews — don't fight it).
A LISTED paid service must stay reachable 24/7 (idle suspend + auto update
restarts work against this) → read references/selling.md § Always on
availability BEFORE publishing for the update mode check/flip flow.
Buy — pay other agents' x402 services
Quick Start — preset CLI scripts (use these FIRST, no custom code)
One process per step, ONE JSON object on stdout — no per call LLM reasoning
about balances/signatures/rail selection needed:
Raw client (advanced / custom flows):
Pre flight FIRST (one round trip, not serial walls)
Before asking the user to confirm any purchase, run
client.payment preflight(amount atomic, networks=<the 402's accept
networks ) and present ALL blockers together. It checks in one shot:
① signers reachable, ② wallet policy sanity — an ENABLED policy with EMPTY
rules is deny all and rejects every signature (new Privy wallets should be
allow all; if found, propose a policy card and get it signed BEFORE paying),
③ USDC balance per candidate rail (direct RPC). If no rail is funded, offer
every option at once — pay from another funded chain, bridge, or
fiat onramp — never a bare "fund the wallet" that leads to the next wall.
Never let the user fix funding, then discover a policy block, then a
dependency error in three separate round trips.
Dependencies : the buyer path needs web3 =7 . If the machine pins an
older web3 (trading bots often pin 6.x), NEVER upgrade it globally — run
bash skills/x402/scripts/ensure env.sh (zero interaction, idempotent): it
creates an isolated .venv x402 immune to PIP USER / PYTHONPATH /user site
interference (venv built without pip + PYTHONNOUSERSITE=1 ) and prints
the interpreter to use on the last stdout line. payment preflight detects
the version conflict and points here. Do this at setup, not mid purchase.
Multi chain selection (buyer receives multiple accepts)
When a service returns 402 with accepts as a list (one entry per
network, e.g. Base + Monad + Robinhood + X Layer + Solana), the buyer Agent does NOT need to ask the user
which chain to use — chain selection is fully automatic in both
paid request and bazaar pay . The logic:
1. payment preflight (run BEFORE confirming): checks USDC balance on
every candidate rail and returns funded rails[] . If multiple rails are
funded, the automatic selector picks the best one. If NO rail is funded,
present ALL funding options at once (bridge, on ramp, pay from another
chain) — never ask "which chain?" when the answer is "none of them".
2. A