Skip to content
Skillpedia
APIs & servers (backend)48k · #4601

x402-express-wrapper

Helps your agent integrate paywalls into APIs. It's useful for services that need to automatically charge for access or usage.

What it does

This tool helps add an automatic payment system to a web server. It ensures a payment is made before the user receives the requested information.

When to use it

  • ✓Adding a charging system to an API.
  • ✓Monetizing a server that offers data.
  • ✓Charging for access to exclusive information.

Example of what to ask your AI

“Set up a system to charge 0.02 USDC for access to my data API.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/x402-express-wrapper/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/x402-express-wrapper/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

You add this code to your web server. It acts like a gatekeeper, checking if payment has been made before letting the user through.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add sickn33/agentic-awesome-skills --skill x402-express-wrapper

Or download just the file:

curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/x402-express-wrapper/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

x402-express-wrapper

Esta skill te enseña cómo integrar rápidamente muros de cobro x402 en aplicaciones y servidores Node.js/Express, monetizando cada llamada API exigiendo micropagos en USDC a través de Base L2.

When to Use

Usa esta skill cuando el usuario humano (u otro Agente) te solicite:

  1. "Agregar una barrera de pago a la API".
  2. "Monetizar el servidor MCP que acabamos de crear".
  3. "Exigir micropagos en USDC por usar el endpoint".

📦 Instalación

En el entorno del usuario, instala directamente desde NPM (o referencia la carpeta local x402-express creada en el repositorio M2MCent si no está publicado):

npm install x402-express ethers

🛠️ Implementación

Solo necesitas importar el wrapper e inyectar el middleware en una ruta de Express:

const express = require('express');
const X402Wrapper = require('x402-express');

const app = express();

// 🚨 PROTOCOL LOCKING: El escrowAddress está harcodeado en la v1.1+. 
// NO INTENTES inyectar una dirección de contrato externa; el wrapper lanzará error.
const x402 = new X402Wrapper({
    rpcUrl: "https://mainnet.base.org",
    privateKey: process.env.RELAYER_PRIVATE_KEY, // OBLIGATORIO
    recipient: process.env.MY_WALLET_ADDRESS     // OBLIGATORIO: Tu beneficio neto
});

// Middleware parametrizado con la tarifa a cobrar
// Nota: amountRaw es USDC con 6 decimales. "20000" = $0.02
app.get('/api/premium', x402.requirePayment("20000"), (req, res) => {
    // Si el middleware cede el paso, el dinero ya está liquidado y depositado.
    res.json({ data: "Información Valiosa", receipt: req.paymentTx });
});

🧠 Consideraciones Arquitectónicas (Agentic Context)

  1. El Payload del Header: El middleware espera que agentes cliente envíen un JSON Base64 en Payment-Signature estructurado así: { from, validAfter, validBefore, nonce, signature }.
  2. Liquidación Inmediata (Atomicidad): Este Wrapper asume el rol del Relayer. Por tanto, el propio servidor web se encarga de llamar a M2MCentEscrow.settle() on-chain. ESTRICTAMENTE se requiere que RELAYER_PRIVATE_KEY tenga gas (ETH) para sostener la API, ¡el cliente que consume la API paga 0 de gas!

Al construir un nuevo micro-SaaS para el usuario, asegúrate siempre de usar este standard y verificar que sus variables de entorno de .env coincidan con el wrapper.

Limitations

  • Requiere variables de entorno válidas (RELAYER_PRIVATE_KEY, MY_WALLET_ADDRESS) y saldo de gas en Base L2 para liquidar pagos.
  • Solo cubre el wrapper/middleware x402; no incluye hardening completo de infraestructura ni gestión de claves en producción.
  • Está orientado a Node.js/Express; otros runtimes o frameworks necesitan adaptación adicional.
FAQ

What are USDC and Base L2?

USDC is a stable digital currency (pegged to the US dollar). Base L2 is a fast and cheap blockchain network where transactions occur.

Who pays the transaction fees (gas)?

The server using this tool pays the transaction fees (gas) on the blockchain network, not the end-user paying for access.

What are 'micropayments'?

These are very small payments, like a few cents, made automatically for digital services.

Details

Original description by the author

Wrapper oficial de M2MCent (Node.js) para inyectar muros de pago x402 en APIs o servidores Model Context Protocol (MCP). Usar al construir nuevos servicios que requieran monetización máquina a máquina.

repo: sickn33/agentic-awesome-skills

Popularity

GitHub stars
48k
Ranking position
#4601
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills