Skip to content

Direction for durable viem-chain freshness in x402 SDKs #2296

@ryanRfox

Description

@ryanRfox

Background

#1971 closed via #2054 which is a different layer than the options @cryptomotifs sketched. Reopening as a fresh issue since the close didn't address this design layer.

The dependencies bug

The visible symptom was Mezo (eip155:31611) missing from published bundles. The real bug surfaced by @cryptomotifs:
x402 can't distinguish "chain exists in viem ≥ N but we're pinned on < N"
(freshness gap; throws Unsupported chain ID when the chain is in fact
supported) from "chain truly doesn't exist" (correct error).

A lockfile bump postpones the first case until the next new chain. A runtime registry fixes the distinction.

Three options (per @cryptomotifs, ordered by effort vs. robustness)

  1. Runtime fetch + minimal local fallback — small x402-chains package lazy-fetches chain metadata from a CDN JSON endpoint, with compiled-in fallback for the offline-must-work subset. Decouples downstream SDKs from viem's release cadence entirely, but introduces infrastructure requirements.
  2. defineChain by ID, per-chain literals committed here — viem for types only. Scoped variant I floated:
    paywall sources from x402's existing per-chain registries (e.g. DEFAULT_STABLECOINS in @x402/evm).
  3. Weekly Dependabot lockfile refresh — drafted as chore: add scoped viem dependabot updates for /typescript #2002 which narrows the freshness gap but doesn't fix the UX distinction.

Status

Ask

@phdargen — looking for guidance on which of options 1 or 2 is the direction we should consider for a robust fix, as I don't have context to pick between them. Merging #2002 seems to be a fine mitigation step in the meantime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions