feat(examples): add x402 survival check — pre-payment cashier on Base mainnet#1255
Open
This-Is-Hellgate wants to merge 1 commit into
Open
feat(examples): add x402 survival check — pre-payment cashier on Base mainnet#1255This-Is-Hellgate wants to merge 1 commit into
This-Is-Hellgate wants to merge 1 commit into
Conversation
🟡 Heimdall Review Status
|
… mainnet Add a Second Eyes survival-check example: an autonomous agent runs a low-cost cashier pre-check over x402 before committing to a larger paid tool call. - x402 v2 client APIs (x402Client + wrapFetchWithPayment + registerExactEvmScheme) - sessionless /api/bar/x402/help-me as canonical first call, optional should-i-pay pre-check - unpaid probe inspects HTTP 402 PAYMENT-REQUIRED before paying - Base eip155:8453, USDC, ExactEvmScheme; $0.01 launch pricing - @secondeyes/mcp-unblock@1.2.3; Polygon/Solana noted as planned, not active - signer is AgentKit's CdpEvmWalletProvider (CDP wallet on Base)
9e57a52 to
88821dc
Compare
Author
|
Hi @murrlincoln — when you have a chance, could you take a look at this example? I updated the PR to current x402/Second Eyes behavior before asking for review:
I also squashed the branch to a single clean commit so the patch no longer contains the stale v1 / Known caveat: the example is new and the lockfile has not been regenerated here because my local environment produced large unrelated pnpm-lock churn. If Coinbase prefers, I can update the lockfile in whatever format/process you recommend. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
typescript/examples/x402-survival-check/— a minimal AgentKit script showing an autonomous agent paying $0.01 USDC on Base mainnet over x402 v2 for a Second Eyes cashier check before spending on more expensive x402 tools.The example uses
CdpEvmWalletProvideras the x402 signer and the x402 v2 client (x402Client+wrapFetchWithPaymentfrom@x402/fetch, exact EVM scheme registered viaregisterExactEvmSchemefrom@x402/evm) — the same building blocks AgentKit'sx402ActionProvideruses internally. It runs against the live production endpoint at secondeyesai.com. No mock server.For MCP-native agents, the same flow is available via
@secondeyes/mcp-unblock@1.2.3(enter_lounge→order_servicewith slughelp-meorshould-i-pay,MCP_X402_WALLET_KEY).Flow
GET /api/bar/x402/help-me→ HTTP 402 PAYMENT-REQUIRED; the agent inspectsaccepts[](schemeExactEvmScheme, networkeip155:8453, USDC on Base, $0.01)PAYMENT-SIGNATURE/X-PAYMENT, settlement proof returns on thepayment-responseheader → HTTP 200 with guidance pack + receipthelp-meis the canonical sessionless distress door (no lounge session header). SetRUN_SHOULD_I_PAY=1to also buy the optional sessionlessshould-i-paychecklist first.Protocol / network
HTTP 402 PAYMENT-REQUIRED→PAYMENT-SIGNATURE/X-PAYMENT→payment-responsesettlement headerExactEvmScheme(EIP-3009), asset Base USDC, networkeip155:8453(the only active Second Eyes settlement network)Motivation
Autonomous agents with CDP wallets increasingly hit HTTP 402 paywalls. Paying blindly wastes USDC on tools that free samples, bar tabs, or cheaper routes would cover. A cheap pre-payment check ($0.01) is a practical guardrail — complementary to pre-broadcast transaction guards.
Related community discussion:
This PR does not implement a new action provider; it is a focused runnable example agents can copy before wiring
x402ActionProviderinto tool loops.What changed in this update
This commit modernizes the previously-stale example to current Second Eyes / x402 canon:
ExactEvmSchemeV1/@x402/evm/exact/v1/clientwith the v2 client (x402Client+registerExactEvmScheme).package.jsonalready pinned@x402/{evm,fetch}@^2.7.0; the code now matches./api/bar/x402/help-me(plus optional/api/bar/x402/should-i-pay), replacing the session-scoped/api/bar/services/should-i-pay+/api/bar/enterflow.eip155:8453(was aliasbase).@secondeyes/mcp-unblock@1.2.3(was1.1.0).PAYMENT-REQUIREDbefore paying.Test plan
eslintclean (pnpm lintin the example) — incl. JSDoc rulesprettier --checkclean (pnpm format:check)@x402/fetch@2.7.0+@x402/evm@2.7.0(tsc --noEmiton the changed import/usage)pnpm install && pnpm buildfromtypescript/root (see caveat below).env.example→.env, set CDP credentials + wallet secretpnpm startfrom the example dir → unpaid 402 probe → paid 200 → BaseScan tx loggedNotes for reviewers
typescript/pnpm-lock.yaml, so a strict--frozen-lockfileCI install will fail until the lockfile is regenerated. A scoped lockfile update on this machine pruned hundreds of unrelated monorepo snapshot entries, so it was intentionally not committed to avoid a large/ risky lockfile churn. Please regenerate the lockfile (pnpm installattypescript/root) in a clean environment and commit that separately, or advise the preferred approach.eip155:8453; the example defaults toNETWORK_ID=base-mainnet.defaultguidance; the agent applies the checklist to its own context (not a server-side yes/no verdict).🤖 Generated by Computer