Use SvelteKit with 4Mica by running the Node adapter behind an Express server. Mount the 4Mica middleware before the SvelteKit handler for paid API routes.
This integration is not stable yet. For now, use the
NodeJS quick start for the supported implementation.
Deposit collateral for the buyer wallet before making paid requests. Match the network in the client scheme and the protected route.To learn more about collateral setup, see Deposits and Withdrawals.
After building SvelteKit with the Node adapter, create an Express server entry that mounts paid routes first and then passes everything else to SvelteKit.
import express from "express";import { handler } from "./build/handler.js";import { paymentMiddlewareFromConfig } from "@4mica/x402/server/express";const server = express();server.use(express.json());server.use( paymentMiddlewareFromConfig( { "GET /api/premium-content": { accepts: { scheme: "4mica-credit", price: "$0.10", network: "eip155:84532", payTo: process.env.PAY_TO ?? "0xYourAddress", }, description: "Access to premium SvelteKit content", }, }, ),);server.get("/api/premium-content", (req, res) => { res.json({ message: "Paid content from SvelteKit" });});server.use(handler);server.listen(3000);