Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(x402): agent custodial wallets as a payment method in the shared checkout

nirholas2a4b48aa7192
diff --git a/docs/tutorials/pay-for-x402-service.md b/docs/tutorials/pay-for-x402-service.md
index bd04f797e..4f445e274 100644
--- a/docs/tutorials/pay-for-x402-service.md
+++ b/docs/tutorials/pay-for-x402-service.md
@@ -6,7 +6,7 @@ This is the **consume** side of x402. If you want to *build* an endpoint that ta
**Prerequisites:**
-- A browser wallet: **Phantom** (or Solflare) for Solana, or **MetaMask** / **Coinbase Wallet** for Base (EVM). The checkout detects whichever is installed. **Or no browser wallet at all:** if you're signed in to three.ws and one of your agents holds USDC in its own wallet, the checkout offers that agent as a payment method and settles server-side — no extension, no popup (see "Paying" below).
+- A browser wallet: **Phantom** (or Solflare) for Solana, or **MetaMask** / **Coinbase Wallet** for Base (EVM). The checkout detects whichever is installed. **Or no browser wallet at all:** if you're signed in to three.ws and one of your agents holds USDC in its own wallet, the checkout offers that agent as a payment method and settles server-side, with no extension and no popup (see "Paying" below).
- A small USDC balance on the network you'll pay from. Most calls are $0.001–$0.01, so ~$1 USDC funds thousands of them. On Solana you also need a little SOL for the account; on Base the signature is gasless from your side.
- Light JavaScript familiarity for the programmatic path (Steps 5–6). The UI paths (Steps 2–4) need none.
@@ -38,7 +38,7 @@ There are two distinct problems: **finding** an endpoint and **paying** it.
- For **Solana**, the wallet can only sign serialized transactions, so the module posts the challenge's `accept` to `/api/x402-checkout?action=prepare` (`api/x402-checkout.js`), gets back a partially-signed SPL `transferChecked`, has Phantom add the buyer's signature, then `?action=encode`s it into the `X-PAYMENT` header.
- For **Base / EVM**, the wallet signs an EIP-3009 `transferWithAuthorization` typed-data message locally — no server prep needed.
-- For an **agent wallet** (signed-in three.ws users only), no browser wallet is involved at all. The modal lists your agents with their live USDC balances (from `/api/x402-pay?agents=1`), and picking one sends the payment through `POST /api/x402-pay` — the server decrypts the agent's custodial key (audit-logged), enforces the agent's per-call/daily spend policy *before* signing, builds and settles the SPL transfer, and streams progress back. Underfunded agents render disabled with their exact balance; the option pays Solana USDC only, and never appears on third-party merchant embeds (the session cookie doesn't travel cross-origin).
+- For an **agent wallet** (signed-in three.ws users only), no browser wallet is involved at all. The modal lists your agents with their live USDC balances (from `/api/x402-pay?agents=1`), and picking one sends the payment through `POST /api/x402-pay`: the server decrypts the agent's custodial key (audit-logged), enforces the agent's per-call/daily spend policy *before* signing, builds and settles the SPL transfer, and streams progress back. Underfunded agents render disabled with their exact balance; the option pays Solana USDC only, and never appears on third-party merchant embeds (the session cookie doesn't travel cross-origin).
Either way the signed payload is base64-encoded into `X-PAYMENT`, the gated request is retried once, and the unlocked result plus the decoded `X-PAYMENT-RESPONSE` receipt come back.
@@ -68,7 +68,7 @@ Find an HTTP service you want and click **Try it** on its card.
1. The drop-in payment modal opens, having already re-fetched the live 402 challenge to confirm the current price (prices can change; the card is a cached hint, the modal is the source of truth).
2. The modal shows the **price**, the **network**, and **who you're paying** — the on-chain `payTo` address, linked to a block explorer so you can verify the recipient before committing.
-3. Pick your wallet. The modal only offers wallets that match a network in the challenge's `accepts` and are actually detected in your browser; undetected ones render disabled with an "install" hint. Signed-in users with funded agents also see a **"Your agents"** group at the top — picking one skips the wallet popup entirely and pays from the agent's own USDC under its spend limits.
+3. Pick your wallet. The modal only offers wallets that match a network in the challenge's `accepts` and are actually detected in your browser; undetected ones render disabled with an "install" hint. Signed-in users with funded agents also see a **"Your agents"** group at the top; picking one skips the wallet popup entirely and pays from the agent's own USDC under its spend limits.
4. Approve the payment in your wallet. Before prompting you, the modal does a fail-open balance pre-check — if it can positively read that your wallet is short, it shows an insufficient-funds state with the exact shortfall and an explorer link, instead of letting you sign a doomed transaction.
5. The platform settles on-chain and retries the call. The card's receipt area fills in with the result and a link to the on-chain transaction.
diff --git a/docs/ux-flows/09-x402-agent-commerce.md b/docs/ux-flows/09-x402-agent-commerce.md
index 51370309b..354402ab9 100644
--- a/docs/ux-flows/09-x402-agent-commerce.md
+++ b/docs/ux-flows/09-x402-agent-commerce.md
@@ -8,7 +8,8 @@ files under `pages/` or `public/`.
The cluster's spine is the **x402 pay-per-call** loop: hit a paid endpoint → get
`402 Payment Required` with `paymentRequirements` → pay (server-held agent wallet,
-or the user's Phantom/MetaMask wallet via the shared `/x402.js` modal) → re-send the
+or the user's Phantom/MetaMask wallet, via the shared `/x402.js` modal, which also
+offers a signed-in user's own agents as server-side payers) → re-send the
request with an `X-PAYMENT` header → facilitator verifies + settles on-chain →
endpoint runs and returns the result. The "agent economy" demos wrap this loop in a
choreographed two-agent narrative driven by Server-Sent Events.
diff --git a/public/x402.js b/public/x402.js
index 19c45bcb4..e432c3416 100644
--- a/public/x402.js
+++ b/public/x402.js
@@ -1334,7 +1334,7 @@ class CheckoutModal {
(buttons.length ? `<div class="x402-wallet-group-label">Browser wallets</div>${buttons.join('')}` : '')
: buttons.join('');
const trustLine = agentButtons.length
- ? 'Agent wallets pay from their own balance under your spend limits — no popup. Browser wallets ask you to approve in the wallet. Settled on-chain either way.'
+ ? 'Agent wallets pay from their own balance under your spend limits, with no popup. Browser wallets ask you to approve in the wallet. Settled on-chain either way.'
: 'You approve the payment in your own wallet — funds move only when the service runs, settled on-chain.';
this.bodyEl.innerHTML = `
${this.renderSteps('connect', { discover: 'done' })}
@@ -1551,7 +1551,7 @@ class CheckoutModal {
// Agent wallets settle Solana USDC only (api/x402-pay pins the mint), so
// only look them up when this checkout offers that rail. The fetch runs in
// the background and injects the extra buttons into the picker when it
- // lands — the browser-wallet buttons never wait on it.
+ // lands; the browser-wallet buttons never wait on it.
if (solana) {
if (this.agentWallets === undefined) this.agentWallets = null;
fetchAgentWallets().then((list) => {
@@ -1650,7 +1650,7 @@ class CheckoutModal {
}
}
- // Pay from an agent's custodial wallet — the whole build/sign/settle happens
+ // Pay from an agent's custodial wallet: the whole build/sign/settle happens
// server-side in /api/x402-pay under the agent's spend policy, streamed back
// as SSE so the step timeline stays live. No wallet popup at any point.
async runAgentWallet(accept, agent) {
@@ -1662,7 +1662,7 @@ class CheckoutModal {
const decimals = Number(accept.extra?.decimals ?? 6);
const priceUsdc = Number(accept.amount) / 10 ** decimals;
try {
- // Pre-flight shortfall guard from the balance the picker already loaded —
+ // Pre-flight shortfall guard from the balance the picker already loaded;
// same UX contract as assertBalance, no extra RPC read. The server
// re-checks everything authoritatively before signing.
if (typeof agent.usdc === 'number' && agent.usdc < priceUsdc) {
@@ -1681,7 +1681,7 @@ class CheckoutModal {
this.renderProgress('connect', { text: `Using ${agentName}'s wallet…` });
const csrfToken = await fetchCsrfToken();
if (!csrfToken) {
- throw new Error('Your three.ws session has expired — sign in again to pay from an agent wallet.');
+ throw new Error('Your three.ws session has expired. Sign in again to pay from an agent wallet.');
}
this.renderProgress('authorize', { text: `Paying ${formatAmount(accept.amount, decimals)} USDC from ${agentName}'s wallet…` });
const final = await payFromAgentWallet(
@@ -1704,7 +1704,7 @@ class CheckoutModal {
}
},
);
- _agentWalletsCache = null; // the balance just changed — next picker rereads it
+ _agentWalletsCache = null; // the balance just changed; the next picker rereads it
const payment = {
transaction: final?.payment?.tx || null,
network: final?.payment?.network || accept.network,
@@ -1725,7 +1725,7 @@ class CheckoutModal {
return;
}
// Spend-policy refusals arrive with the server's own explanation
- // (daily cap, per-call cap, frozen wallet) — surface them verbatim.
+ // (daily cap, per-call cap, frozen wallet): surface them verbatim.
this.renderError('authorize', friendlyError(err));
}
}
diff --git a/tests/public/x402-modal-dom.test.js b/tests/public/x402-modal-dom.test.js
index e293e24b2..e47df4fa3 100644
--- a/tests/public/x402-modal-dom.test.js
+++ b/tests/public/x402-modal-dom.test.js
@@ -158,7 +158,7 @@ describe('x402 payment modal — trust + a11y', () => {
// ── Agent-wallet payment method ──────────────────────────────────────────────
// A signed-in user's agents (each with a custodial Solana wallet) appear in the
-// picker and settle server-side via POST /api/x402-pay — no wallet popup. These
+// picker and settle server-side via POST /api/x402-pay with no wallet popup. These
// tests fake the three session-bound endpoints (?agents=1, /api/csrf-token, the
// SSE settle) and assert the picker, the funded/short gating, and that the
// resolved envelope keeps the browser-path shape ({ ok, result, payment }).
@@ -180,7 +180,7 @@ function sseResponse(events) {
};
}
-describe('x402 payment modal — agent wallet method', () => {
+describe('x402 payment modal: agent wallet method', () => {
const TX = 'AgentTxSig1111111111111111111111111111111111';
let agents;
let payPosts;
@@ -237,7 +237,7 @@ describe('x402 payment modal — agent wallet method', () => {
expect(funded.textContent).toContain('Scout');
expect(funded.textContent).toContain('5.00 USDC');
- // 0.001 USDC cannot cover the 0.01 USDC price — offered but disabled.
+ // 0.001 USDC cannot cover the 0.01 USDC price: offered but disabled.
const broke = document.querySelector('[data-agent-wallet="agent-2"]');
expect(broke.disabled).toBe(true);
expect(broke.textContent).toContain('short');