Release funds, charge payments, process refunds, and query escrow state with @x402r/merchant
The @x402r/merchant package provides everything merchants need for the post-payment lifecycle: releasing escrowed funds, charging directly, processing refunds, and querying operator state.
Looking for server setup? The Merchant Server Quickstart shows how to accept escrow payments via Express middleware. This page covers the X402rMerchant class for managing payments after they arrive.
Use release() to transfer escrowed funds to the receiver (merchant). The amount parameter is required and specifies the exact amount to release in token units.
For partial releases, specify a smaller amount. The remaining funds stay in escrow and can be released or refunded later.
Copy
// Release 3 USDC of a 10 USDC escrowconst { txHash } = await merchant.release(paymentInfo, BigInt('3000000'));console.log('Partial release:', txHash);// Check what remainsconst { capturableAmount } = await merchant.getPaymentAmounts(paymentInfo);console.log('Remaining in escrow:', capturableAmount); // 7000000n
The amount parameter is always required. There is no default “release all” behavior. Always query getPaymentAmounts() first to determine the available capturable amount.
Use charge() for non-escrow flows such as subscriptions or session-based payments. This pulls funds directly from the payer via a token collector (e.g., ERC-3009 transferWithAuthorization).
The charge() method is designed for recurring payments and session-based billing where funds are not pre-escrowed. The token collector contract handles the actual token transfer.
Use refundPostEscrow() to refund funds that have already been released to the receiver. This requires a token collector to source the refund from the merchant’s balance.
This method scans event logs. Pass fromBlock to limit the scan range if your RPC limits eth_getLogs responses (Base Sepolia typically caps at 10,000 blocks).