viem. Your resource server owns pricing, builds the accepts challenge, and
calls Meridian to settle the signed payment. The browser requests the resource,
signs the selected payment requirement, and resubmits the signed payload.
If you only need the shortest possible path on one network, start with the
Quickstart. This guide adds multi-chain challenges, requirement
selection, and error handling on top of it.
Prerequisites
- A frontend with wallet connection (MetaMask, WalletConnect, etc.)
- A protected resource endpoint that returns an x402
402 Payment Requiredchallenge - A server-side Meridian API key for the resource server
Installation
Environment Setup
Keep the Meridian API key on your server. The browser only needs to know your resource URL.Client Implementation
1. Wallet Connection
2. Request the Protected Resource
Request the resource without payment first. A402 response carries the
challenge with one payment requirement per accepted source chain.
3. Select the Payment Requirement
Pick theaccepts entry whose network matches the buyer’s connected chain.
A requirement is source-chain specific — a Base entry cannot be paid from Ink,
because the EIP-712 signature domain includes the source chain id and source
token contract.
4. Sign and Retry
Sign the EIP-3009TransferWithAuthorization as typed data and resubmit the
request with the signed payload. The verifying contract is the token
(requirement.asset), not the facilitator, and authorization.to is the
facilitator (requirement.payTo).
On chains whose payment token does not support EIP-3009 (MegaETH, BSC, BOT
chain, Tempo), the buyer signs a Permit2 witness instead of
TransferWithAuthorization. That is a separate payload shape and signing
flow, not a small variation of the code above. See the non-EIP-3009
guide for the Permit2 implementation.Server Responsibilities
Your resource server must not trust buyer-supplied pricing, recipient, network, or token data. Build or look up the matchingpaymentRequirements server-side,
validate that the signed payload is bound to that requirement, then settle the
buyer’s paymentPayload through Meridian:
paymentRequirements object per source
chain in accepts. Set network, asset, and payTo for the source chain,
then set extra.destinationChainId to the destination chain where Meridian
should settle after Across fills. Add extra.creditedRecipient when the payout
should go to a specific merchant or marketplace recipient — see
Marketplace Fees.
The full request shape, including cross-chain and Permit2 payloads, is
documented in Settle x402 Payment.