Skip to main content
This guide walks you through setting up an Express server that accepts x402r escrow-backed payments. By the end, you’ll have a paid API endpoint protected by the x402 payment middleware with refundable escrow support.

Prerequisites

  • Node.js 20+
  • A deployed PaymentOperator contract (Deploy Operator)
  • A running facilitator service
  • Base Sepolia ETH for testing

Setup

1

Create project and install dependencies

2

Configure environment variables

Create a .env file in the project root:
3

Create the server

Create index.ts:
4

Start the server

You should see:
5

Test the endpoint

Without a valid payment header, the server responds with HTTP 402 and the auth-capture payment requirements:

How it works

  • extra config declares the captureAuthorizer, capture/refund deadlines, fee recipient, and fee bounds. The canonical AuthCaptureEscrow and token collector addresses are universal CREATE2 deploys, so routes do not need to repeat them.
  • AuthCaptureEvmScheme registers the auth-capture payment scheme with the x402 resource server so it can verify auth-capture-backed payments.
  • paymentMiddleware intercepts requests, checks for a valid payment header, and returns 402 when the caller has not provided one.
  • HTTPFacilitatorClient connects to the facilitator service that verifies and settles payments on-chain.

Next Steps

forwardToArbiter()

Forward escrow settlements to an arbiter service.

Merchant SDK

Capture payments, handle refunds, and manage escrow.

Deploy Operator

Deploy your own PaymentOperator contract.