TypeScript · Express.js

TypeScript · Express
npm install @metapay402/express

import express from "express";
import { paywall, initMetaPay, MetaPayConfig } from "@metapay402/express";

const app = express();

initMetaPay(new MetaPayConfig({
  walletAddress: "YOUR_WALLET_ADDRESS",
  tokenMint: "USDC_MINT_ADDRESS"
}));

app.get("/premium",
  paywall({ price: "0.10" }),
  (req, res) => res.json({ ok: true })
);

app.listen(3000, () => console.log("Ready on :3000"));

Python · FastAPI

Python · FastAPI
pip install metapay402-fastapi

from fastapi import FastAPI
from metapay402_fastapi import paywall

app = FastAPI()

@app.get("/premium")
@paywall(
    price="0.10",
    wallet="YOUR_WALLET_ADDRESS",
    token="USDC_MINT_ADDRESS"
)
async def premium():
    return {"ok": True}

Auto-paying client

Clients can automatically handle HTTP 402 responses and complete the payment flow.

Clients
// TypeScript
import { X402AutoClient } from '@openlibx402/client';
import { Keypair } from '@solana/web3.js';

const client = new X402AutoClient(Keypair.generate());
const res = await client.get('https://api.example.com/premium');
console.log(res.data);

# Python
from openlibx402_client import X402AutoClient
from solders.keypair import Keypair

client = X402AutoClient(wallet_keypair=Keypair())
res = await client.fetch('https://api.example.com/premium')
print(res.json())

For full details, see the repository.

Open GitHub