Quickstart for Merchants / Sellers
This guide walks you through integrating RailBridge x402 payments into your Express.js application to accept same-chain or cross-chain payments.
1. Prerequisites
2. Install x402 Packages
npm install @x402/express @x402/core @x402/evm @x402/paywall3. Configure Environment Variables
4. Basic Setup
import express from "express";
import { paymentMiddleware } from "@x402/express";
import { x402ResourceServer } from "@x402/core/server";
import { HTTPFacilitatorClient } from "@x402/core/http";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
import { createPaywall } from "@x402/paywall";
import { evmPaywall } from "@x402/paywall/evm";
const FACILITATOR_URL = process.env.FACILITATOR_URL || "https://facilitator.railbridge.io";
const MERCHANT_ADDRESS = process.env.MERCHANT_ADDRESS as `0x${string}`;
// Create facilitator client
const facilitatorClient = new HTTPFacilitatorClient({ url: FACILITATOR_URL });
// Create resource server
const resourceServer = new x402ResourceServer(facilitatorClient);
// Register EVM scheme
registerExactEvmScheme(resourceServer, {
networks: [
"eip155:84532", // Base Sepolia
"eip155:8453", // Base Mainnet
"eip155:1", // Ethereum Mainnet
"eip155:11155111", // Ethereum Sepolia
"eip155:137", // Polygon
],
});
// Create paywall for browser requests
const paywall = createPaywall()
.withNetwork(evmPaywall)
.withConfig({
appName: "Your App Name",
testnet: true, // Set to false for mainnet
})
.build();
const app = express();
app.use(express.json());5. Same-Chain Payment Integration
6. Cross-Chain Payment Integration
7. Multiple Payment Options
8. Accessing Payment Information
9. Error Handling
10. Advanced: Logging and Monitoring
11. Complete Example: Same-Chain
12. Complete Example: Cross-Chain
13. Testing Your Integration
14. Common Issues and Solutions
Last updated
