@faremeter/payment-evm
@faremeter/payment-evm implements the Coinbase x402 exact scheme on EVM chains. It provides:
Source: GitHub › packages/payment-evm
- A client handler that signs EIP-3009
TransferWithAuthorizationpayloads using a local or Ledger-backed wallet. - A facilitator handler that validates client payloads, verifies signatures, and submits the transfer on-chain.
- Shared constants and type guards you can reuse in custom flows.
transferWithAuthorization. Asset metadata (contract addresses, forwarders, etc.) comes from @faremeter/info/evm.
Quick start
Modules
exact/createPaymentHandler(wallet, opts?)
Creates a PaymentHandler compatible with @faremeter/fetch.
wallet: object exposing{ chain, address, account }whereaccount.signTypedDatafollows the viem signature contract.@faremeter/wallet-evmand@faremeter/wallet-ledgerreturn compatible wallets.opts.asset: asset to request. Accepts token symbols defined in@faremeter/info/evmor custom contract descriptors ({ address, contractName, ... }).
- Detects the x402 network from
wallet.chain.idand validates the asset. - Filters incoming requirements to ones matching the network + asset.
- For each match, returns a
PaymentExecerthat:- Generates an EIP-3009 authorization (nonce, validity window).
- Validates/augments EIP-712 domain details from the requirement payload.
- Signs typed data with the wallet and returns
{ payload: { authorization, signature } }.
payTo is not a valid EVM address or when domain metadata is malformed.
exact/createFacilitatorHandler(chain, privateKey, asset, opts?)
Creates a FacilitatorHandler suitable for @faremeter/facilitator.
chain:ChainInfo(id, RPC URLs) describing the network you serve.privateKey: EVM private key used to submit transactions. Must pass@faremeter/types/evm.isPrivateKey.asset: token symbol or explicit asset info understood by@faremeter/info/evm.opts.network: override the x402 network identifier if it differs fromchain.id.opts.transport: custom viem transport (defaults tohttp(chain.rpcUrls.default.http[0])).
getSupported: returns the supported{ scheme: "exact", network, x402Version: 1 }.getRequirements: filters incoming requirements and fills:asset: resolved contract address.maxTimeoutSeconds: 300 (5 minutes).extra: EIP-712 domain metadata (chainId, verifying contract, etc.).
handleSettle: validates the payload (x402ExactPayload), checks amount and destination, verifies on-chain nonce usage, and broadcasts atransferWithAuthorizationtransaction.
null is returned when the requirement doesn’t belong to this handler, allowing other handlers to try.
Constants and helpers
X402_EXACT_SCHEME: literal"exact".TRANSFER_WITH_AUTHORIZATION_ABI: viem-compatible ABI definitions used for reading/writing USDC authorizations.EIP712_TYPES:TransferWithAuthorizationtyped-data schema.x402ExactPayload: arktype runtime validator for payloads – use it to guard custom integrations.eip712Domain: arktype validator for allowed domain overrides.generateMatcher(network, asset): internal helper that derives a requirements matcher via@faremeter/types/x402.generateRequirementsMatcher.generateDomain(publicClient, chainId, asset): fetches USDC contract name/version to build the EIP-712 domain.generateForwarderDomain(chainId, info): constructs domains when using a forwarder contract.
Usage patterns
- Ledger support: Combine with
@faremeter/wallet-ledger.createLedgerEvmWalletto sign authorizations on a Ledger device while reusing the exact same handler API. - Forwarders: If
@faremeter/info/evmdescribes a forwarder, the facilitator automatically fills theextrafield with the forwarder’s domain metadata. - Custom assets: Extend
@faremeter/info/evmtoken catalog and pass the new symbol asasset. Both client and facilitator will share the same metadata. - Observability: The facilitator emits warnings via
["faremeter","payment-evm"](through Logtape). Capture those during settlement to identify mismatches.
Related references
@faremeter/info/evm: token catalogs and helper lookups used by both handlers.@faremeter/types: x402 schemas,FacilitatorHandler, and validation utilities.@faremeter/fetch&@faremeter/facilitator: client/server orchestration around these handlers.