docs(examples): add x402ActionProvider pre-execution safety guard example - #1417
Open
teodorofodocrispin-cmyk wants to merge 1 commit into
Conversation
…mple Adds a minimal, standalone example showing how to gate an on-chain transaction behind a third-party x402 safety check using the existing x402ActionProvider (no new dependencies on the framework itself). The pattern: build the candidate tx, call an x402-compatible guard service via makeHttpRequestWithX402 (auto-pays the small USDC fee), and only proceed if the verdict is SAFE. Deterministic -- does not depend on the LLM choosing to run the check. Uses SENTINEL (sentinel-agent.dev), an independent/unaffiliated x402 service, purely as a worked example since its response is easy to branch on. The pattern generalizes to any x402-compatible guard service -- swapping GUARD_URL is enough. Verified: TypeScript syntax/type-checks cleanly in isolation (no errors beyond expected unresolved workspace/external packages, which aren't installed outside the monorepo). Not run against the full monorepo build/lint pipeline from this environment -- happy to adjust to match conventions on review.
🟡 Heimdall Review Status
|
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.
What this adds
A minimal, standalone example demonstrating a pattern: gating an on-chain transaction behind a third-party x402 safety check, using the existing
x402ActionProvider-- no new dependencies added to the framework itself.The pattern
to,value,data).makeHttpRequestWithX402(pays the small USDC fee automatically).This is deliberately not wired through the LLM tool-calling loop for the safety decision itself -- the check should run every time, deterministically, regardless of what the model decides. The example calls the action provider's methods directly in code.
About the third-party service used in the example
The example uses SENTINEL as the guard service purely because its response (
verdict/risks/score) is easy to branch on for a clear example. It is independent and unaffiliated with Coinbase/AgentKit -- I'm one of its maintainers, flagging that plainly. The pattern generalizes to any x402-compatible guard service; swappingGUARD_URLand the response-parsing is enough. Happy to genericize this further (e.g. parameterize the guard URL/schema) if that's preferred to naming one service in an official example.Verification
tsc --noEmit --skipLibCheck) -- no errors beyond expected unresolved workspace (@coinbase/agentkit) and external (dotenv) packages, which I don't have installed outside the monorepo.package.json,tsconfig.json, eslint/prettier configs) mirrorstypescript/examples/langchain-cdp-chatbotas closely as possible for consistency, but please flag anything that doesn't match current conventions -- glad to adjust.Files added
typescript/examples/x402-sentinel-preflight-guard/guard-before-transfer.ts-- the example itselfREADME.mdpackage.json,tsconfig.json,.eslintrc.json,.prettierrc,.prettierignore,.env-local