Skip to main content

@faremeter/info

@faremeter/info centralizes metadata and helpers for producing Coinbase x402 payment requirement payloads. It wraps the shared @faremeter/types schemas with typed builders so callers can focus on business logic instead of boilerplate defaults.
  • Compatible with Node 18+ (ESM) and TypeScript 5.2+.
  • Depends on sibling packages @faremeter/types/evm and @faremeter/types/solana for address validation.

Quick start

import { solana, evm } from "@faremeter/info";

const requirement = solana.x402Exact({
  network: "mainnet-beta",
  asset: "USDC",
  amount: "1.5",
  payTo: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
});

const fallback = evm.x402Exact({
  network: "base",
  asset: "USDC",
  amount: 5,
  payTo: "0xabc123...",
});

Export overview

Utility types

  • UnitInput: union of string | number used for human-readable amount inputs while preserving precision when converted to strings.
  • addX402PaymentRequirementDefaults(req): fills description and mimeType with Coinbase x402 defaults before returning the partially constructed requirement. Use it when assembling custom payloads to keep consistency with other builders.

Solana module (solana)

Network helpers
  • KnownCluster, isKnownCluster(value): whitelist and guard for supported clusters (devnet, testnet, mainnet-beta).
  • lookupX402Network(cluster): expands a Solana cluster into the identifiers expected by downstream x402 middleware (adds the plain solana alias for mainnet-beta).
Token catalog
  • KnownSPLToken, isKnownSPLToken(token): currently limited to USDC, extendable in code.
  • lookupKnownSPLToken(cluster, token): returns the mint address and a toUnit helper for formatting amounts, or undefined when the token is unsupported on that cluster.
Requirement builders
  • x402Exact(args): returns an array of payment requirement objects (one per network alias) with scheme exact. Throws if the token/cluster pair is unknown. Internally applies a 60 second timeout to match Coinbase middleware defaults.
  • xSolanaSettlement(args): builds a single requirement using the custom @faremeter/x-solana-settlement scheme. Accepts either "sol" or a KnownSPLToken; throws for unsupported assets.

EVM module (evm)

Network helpers
  • KnownX402Network, isKnownX402Network(name): guard the curated list of Base and SKALE network identifiers.
  • lookupKnownX402Network(name): returns chain metadata (currently just chainId) for known networks.
  • lookupX402Network(chainId): maps a numeric chainId to the known key when possible or falls back to an eip155:{chainId} string.
Asset catalog
  • KnownAsset, isKnownAsset(asset): presently supports USDC.
  • lookupKnownAsset(network, asset): resolves contract metadata, optional forwarder details, and a toUnit helper. Accepts either a known network key or numeric chainId.
  • findAssetInfo(network, assetOrInfo): convenience wrapper that accepts a raw asset name (using the catalog) or a custom ContractInfo object. Throws for unknown assets or unsupported networks.
Requirement builders
  • evm.x402Exact(args): creates a single exact scheme requirement with a 300 second timeout. Throws if the asset is unknown for the specified network.

Usage patterns

Multi-chain payment requirements

import { solana, evm } from "@faremeter/info";

export function buildRequirements(payToSol: string, payToEvm: string) {
  const solanaReqs = solana.x402Exact({
    network: "mainnet-beta",
    asset: "USDC",
    amount: "1.50",
    payTo: payToSol,
  });

  const evmReq = evm.x402Exact({
    network: "base",
    asset: "USDC",
    amount: 2,
    payTo: payToEvm as `0x${string}`,
  });

  return [...solanaReqs, evmReq];
}

Custom requirement with defaults

import { addX402PaymentRequirementDefaults } from "@faremeter/info/common";

const customRequirement = addX402PaymentRequirementDefaults({
  scheme: "exact",
  network: "solana-mainnet-beta",
  payTo: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  maxAmountRequired: "10",
});

Error handling

  • Builder functions throw when asked for unsupported assets, clusters, or networks. Surface these to integrators (e.g., HTTP 400) so they can correct configuration.
  • Catalog guards (isKnownCluster, isKnownSPLToken, isKnownAsset, isKnownX402Network) are designed for pre-validation when consuming user input.

Extending the catalog

When adding new assets or tokens, update the relevant constants in src/solana.ts or src/evm.ts and expand the documentation accordingly. Ensure:
  • The mint/contract addresses are accurate per network.
  • toUnit implementations return stringified amounts in the denomination expected by downstream settlement logic.
  • Tests or examples cover the new asset to prevent regressions.
  • @faremeter/types: canonical x402 schemas and validation helpers.
  • @faremeter/facilitator: consumes these requirement builders when orchestrating multi-network payment flows.