import { Hono } from 'hono';
import { createMiddleware } from "@faremeter/middleware/hono";
const app = new Hono();
const RECEIVING_ADDRESS = process.env.RECEIVING_ADDRESS;
if (!RECEIVING_ADDRESS) {
throw new Error("RECEIVING_ADDRESS environment variable is required");
}
// Free health check endpoint
app.get("/health", (c) => c.json({ status: "healthy" }));
// Free info endpoint
app.get("/info", (c) => c.json({
name: "Simple String Reverser API (SKALE)",
description: "Paid string reversal service on SKALE Base Sepolia testnet",
endpoints: ["/tools/paid/reverse-string"]
}));
// Create payment middleware for SKALE Base Sepolia testnet
const skaleMiddleware = await createMiddleware({
facilitatorURL: "https://facilitator.dirtroad.dev",
accepts: [
{
scheme: "exact",
network: "eip155:2140350733", // SKALE Base Sepolia
maxAmountRequired: "10000", // 0.00001 AxiosUSD
maxTimeoutSeconds: 5000,
payTo: RECEIVING_ADDRESS,
asset: "0x61a26022927096f444994dA1e53F0FD9487EAfcf", // Axios USD
description: "string reversal service",
mimeType: "application/json"
}
]
});
// SKALE testnet paid endpoint
app.post("/tools/paid/reverse-string", skaleMiddleware, async (c) => {
const { str } = await c.req.json();
if (!str || typeof str !== 'string') {
return c.json({ error: "str parameter is required and must be a string" }, 400);
}
const result = str.split('').reverse().join('');
return c.json({
original: str,
result,
network: "skale-base-sepolia"
});
});
export default app;