@openx402/bazaar-sdk is a compiler and metadata helper. It never holds a
secret, signs a payment, calls a facilitator, creates a trustline, or submits a
Stellar transaction. The official x402 middleware remains responsible for
payment handling.
Install the package:
Entry points and exports
The root entry point does not import Stellar SDK or Zod. Sellers using only
bazaar.http do not install those optional integrations accidentally.
Low-level helpers
bazaar.http(config)
Accepts method, service metadata, query/path/body/header parameter maps, body
encoding, and output metadata. It compiles to the official Bazaar declaration:
bazaar.mcp(config)
Reuses the MCP tool’s existing inputSchema and requires toolName. Parameter
descriptions remain in inputSchema.properties; the helper does not create a
second schema language.
Both helpers expose { resource, extensions: { bazaar }, compile() } and delegate
to the upstream @x402/extensions/bazaar builder. Output description is carried
as JSON Schema annotation because the official builder has no separate output
description field.
Seller factory
createX402Seller(config) eliminates duplicated method, path, public URL, asset,
network, timeout, and sponsorship values while keeping the official middleware
as the runtime boundary.
method, path, routeKey, resourceUrl,
paymentConfig, resource, extensions, and compile(). paymentConfig is
keyed as METHOD /path, so it cannot accidentally become a wildcard route.
MCP seller tools
toolName, path, resourceUrl, one resolved
paymentOption, resource, extensions, and compile(). Duplicate tool names
at the same path are rejected. MCP identity remains (resource.url, input.toolName) at catalog time.
Payment inputs and assets
PaymentInput requires an asset alias and an atomic-unit amount:
payment.asset; register a
readable alias in assets. Amounts are string | bigint, never floating-point
JavaScript numbers. extra is merged after extra.areFeesSponsored; the SDK
does not invent other protocol fields.
The optional Stellar registry derives native XLM SAC IDs from the correct
network passphrase and imports USDC addresses from @x402/stellar:
fromZod
fromZod(schema, { example }) converts an object schema to the compiled input
shape while preserving descriptions, enums, optional fields, nested properties,
and required fields. If an example is supplied, it is validated by the same Zod
schema before compilation.
ZodAdapterError with path-aware issues for a non-object schema or an
invalid example. The adapter only compiles discovery metadata; request
validation should still run in the seller’s own handler.
Public URL resolution
resolveSellerPublicUrl uses this precedence:
- explicit
SELLER_PUBLIC_URL/option override; - Railway’s
RAILWAY_PUBLIC_DOMAINas an HTTPS origin; - an explicitly supplied local development URL.