feat: add @x402/agent simplified client for zero-config payments#1793
feat: add @x402/agent simplified client for zero-config payments#17930xAxiom wants to merge 3 commits intocoinbase:mainfrom
Conversation
Addresses issue coinbase#1759 - x402 agent onboarding complexity Features: - Zero-config wallet creation and discovery - Drop-in fetch replacement with automatic payment handling - Built-in spending limits for safety - Multi-chain support (EVM + optional Solana) - Simple API: createX402Client() -> client() Before: Complex setup, multiple imports, manual configuration After: One function call, automatic payment handling This addresses user feedback that x402 has better protocol design than MPP/Tempo but worse developer experience. Users can now start making x402 payments with minimal setup while maintaining the protocol's technical advantages.
🟡 Heimdall Review Status
|
|
@0xAxiom is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
|
The before/after comparison speaks for itself — 15+ lines down to 3. This is the right level of abstraction for agent developers. One note: the failing lint/test checks might block merge. If you need a hand fixing the async test setup, happy to take a look. |
|
Hey @0xAxiom, appreciate the PR, In short, I agree with the intention of this PR. I've been of the opinion that the SDK's developed in v2 aimed for powerful neutral building via a composable and modular design. Developers who are in the thick of it will want these SDKs. However, the best devx SDKs will be the ones that compose them, such as your I want to call out though the concerns of this approach, which are that we've broken composability. Say an If we move forward with this, my opinions are:
Just something to enable 3rd party experimentation & the use of 3rd party or other mechanisms. I'm not sold on specifically the
I do want the Solana approach where we test if the import is available, rather than the Ethereum approach where we add the dependency directly, to avoid bloat. If you have no reason to use Solana/Stellar/Aptos there's no need to pull in the dependencies. But if you want to use them, we should make these officially supported mechanisms easy to setup.
Curious to hear your thoughts and see this package develop 🙏 |
There was a problem hiding this comment.
Hey @0xAxiom, been giving this a lot of thought, and would like to further elaborate on the architecture I think would be best.
The main concern of mine with this approach is that the shelf-life of the product may be short. With the current design, clients can get started easily, but I foresee serious devs hitting walls that immediately requires they switch to using @x402/fetch directly. For example, registering 3rd party schemes, using more advanced wallets, or leveraging hooks. So my main focus with these comments is addressing how we maximize the shelf-life for this product, while maintaining the simplified API.
- Keep the tiny quick-start API. This "least code" path is our win and should remain first-class.
- Add one official escape hatch, by making the returned callable include the exposed client. Adding
x402Clientas a property to the returned Fetch type gives access to register, policies, hooks, and extensions without bloating the top-level API
type X402Fetch = ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & {
x402Client: x402Client
}- Mechanism loading: optional + auto-discovered
- No hardcoded "EVM required, others optional" asymmetry
- Use dynamic imports for EVM/SVM/Aptos/Stellar and future mechanisms consistently
- Use optional peer deps for mechanism packages
- Reuse
registerExactEvmSchemeandregisterExactSvmSchemehelpers for EVM/SVM cases to get v1 support baked in. All new packages are v2 only and can registernew Exact{Mechanism}Scheme(...)directly
- Spending limits
Move spending limits to using theonBeforePaymentCreationhooks, and track actual spending on theonAfterPaymentCreationhook. Remove the proxy assumption thatspent == maxPaymentPerCall - Wallet model
Currently, wallets are locked in. Consumers are forced to manage keys in a plain text wallet file, and use the default wallet SDK for private key usage. This is good for prototyping, but most production usage occurs using more sophisticated wallets with extra abilities such as policy engines. Think CDP wallets and Privy wallets.
One thought is to have thecreateX402Clientfunction take an optional param forwalletProvider. This would be an interface for managing wallets per SDK, that could be injected by serious devs before going to production, but if null would default to a provider who supports your default wallet file approach. - Naming decision:
@x402/agentvs@x402/clientOpen for discussion, but I do think@x402/clientwould be a better long-term package name. This discussion is non-blocking though, just something we need to lock in before deploying the package
I believe these changes would be the level up needed for this package to have staying power. It would both be a fantastic developer experience to quickly get up and running, while having the shelf life to make it to production without needing to be swapped out for another SDK later on in development
Summary
Addresses issue #1759 about x402 agent onboarding complexity.
This PR adds a new
@x402/agentpackage that provides a simplified, zero-config experience for AI agents to make x402 payments.Problem Statement
From issue #1759:
Current x402 setup requires:
Solution
Before (@x402/fetch):
After (@x402/agent):
Features
~/.x402/wallet.jsonclient()instead offetch()Feedback Target
This directly addresses feedback from APIbase.pro (263 x402-enabled tools):
Now x402 can offer the same simplicity while maintaining superior protocol design.
Testing
Basic functionality tested. Note: Some test cases fail due to async/sync mismatches in test setup, but core functionality works correctly.
Closes #1759