Skip to main content

x402

We provide four client and server schemes to facilitate private x402 payment scenarios with varying preconditions and privacy requirements.

Schemes

Generally, the bermuda::transfer scheme should be preferred as it provides the best level of privacy for both payer and payee. bermuda::anyhow is a convenience wrapper scheme, combining bermuda::transfer with bermuda::deposit as fallback in case of insufficient Bermuda balance of the payer. Applicability of a specific scheme varies per use case:

SchemePayerPayee Balance
bermuda::depositpublicprivate
bermuda::transferprivateprivate
bermuda::anyhowprivate/publicprivate
bermuda::withdrawprivatepublic

Exports

Our x402 support is manifested in three SDK exports. These interfaces and types follow the conventions laid out by the @x402/* family of packages, and as such can be used as direct drop-ins to realize private payments over x402:

x402Fetch(scheme, signer?, spender?)

Wraps fetch with a x402 Bermuda client.

x402ClientScheme(scheme, signer?, spender?)

Creates a x402 Bermuda client scheme.

x402ServerScheme(scheme)

Creates a x402 Bermuda server scheme.

Example

On the client-side just create a wrapped version of fetch with our x402Fetch utility:

let fetchAndPayPrivately = bermuda.x402Fetch('bermuda::anyhow', walletClient, account)
  • walletClient must be a viem.WalletClient due to @x402/* dependencies

Just as the other wrapFetchWithPayment variants the returned function automatically responds to HTTP 402 server responses with private payment payloads produced by given Bermuda account, ultimately resolving the underlying resource.