open-index/open-npm huggingface dataset:
npm package: @okxweb3/x402-evm
Description: x402 Payment Protocol EVM Implementation
Author: okfe
Latest version: 0.1.0

# @okxweb3/x402-evm

EVM implementation of the x402 payment protocol for X Layer. Supports EIP-3009 `transferWithAuthorization` and aggregated deferred payment schemes.

## Installation

```bash
npm install @okxweb3/x402-evm
```

## Supported Chain

| Chain | CAIP-2 ID | Default Stablecoin | Transfer Method |
| --- | --- | --- | --- |
| **X Layer** | `eip155:196` | USDT0 | EIP-3009 |

## Supported Schemes

- **exact** — Standard payment. The exact amount is transferred on-chain via EIP-3009 `transferWithAuthorization`.
- **aggr_deferred** — Aggregated deferred payment using session keys. The facilitator batches multiple payments on-chain for high-throughput scenarios.

## Exports

### Main entry (`@okxweb3/x402-evm`)

- `ExactEvmScheme` — Client-side Exact scheme (EIP-3009)
- `AggrDeferredEvmClientScheme` / `AggrDeferredEvmServerScheme` — Aggregated deferred payment scheme
- `toClientEvmSigner(account)` / `toFacilitatorEvmSigner(wallet)` — Convert viem objects to x402 signers
- Type guards: `isEIP3009Payload`

### Subpath exports

| Path | Description |
| --- | --- |
| `@okxweb3/x402-evm/exact/server` | Server-side Exact scheme (builds payment requirements) |
| `@okxweb3/x402-evm/exact/facilitator` | Facilitator Exact scheme (verifies & settles payments) |
| `@okxweb3/x402-evm/deferred/client` | Deferred payment client scheme |
| `@okxweb3/x402-evm/deferred/server` | Deferred payment server scheme |

## Usage

### Client-side (signing payments)

```typescript
import { x402Client } from "@okxweb3/x402-core/client";
import { ExactEvmScheme, toClientEvmSigner } from "@okxweb3/x402-evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0x...");
const signer = toClientEvmSigner(account);

const client = new x402Client()
  .register("eip155:196", new ExactEvmScheme(signer));
```

### Server-side (building payment requirements)

```typescript
import { ExactEvmScheme } from "@okxweb3/x402-evm/exact/server";

const evmServer = new ExactEvmScheme();
```

### Facilitator (verifying & settling payments)

```typescript
import { ExactEvmScheme } from "@okxweb3/x402-evm/exact/facilitator";
import { toFacilitatorEvmSigner } from "@okxweb3/x402-evm";

const facilitator = new ExactEvmScheme(toFacilitatorEvmSigner(walletClient));
```

## Asset Transfer Method

Tokens on X Layer use **EIP-3009** (`transferWithAuthorization`), which provides gasless, single-signature token transfers. The default stablecoin is USDT0.

## Related Packages

- `@okxweb3/x402-core` — Core protocol types and client
npm package: @okxweb3/x402-fastify
Description: x402 Payment Protocol - Fastify middleware
Author: okfe
Latest version: 0.1.0

# @okxweb3/x402-fastify

Fastify middleware for the x402 Payment Protocol. Adds x402 payment requirements to Fastify applications.

## Installation

```bash
npm install @okxweb3/x402-fastify
```

## Quick Start

```typescript
import Fastify from "fastify";
import { paymentMiddleware, x402ResourceServer } from "@okxweb3/x402-fastify";
import { ExactEvmScheme } from "@okxweb3/x402-evm/exact/server";
import { OKXFacilitatorClient } from "@okxweb3/x402-core/server";

const app = Fastify();

const facilitatorClient = new OKXFacilitatorClient();
const resourceServer = new x402ResourceServer(facilitatorClient)
  .register("eip155:196", new ExactEvmScheme());

paymentMiddleware(
  app,
  {
    "GET /protected-route": {
      accepts: {
        scheme: "exact",
        price: "$0.10",
        network: "eip155:196",
        payTo: "0xYourAddress",
      },
      description: "Access to premium content",
    },
  },
  resourceServer,
);

app.get("/protected-route", async () => {
  return { message: "Premium content" };
});

app.listen({ port: 3000 });
```

## API Reference

### paymentMiddleware

```typescript
function paymentMiddleware(
  app: FastifyInstance,
  routes: RoutesConfig,
  server: x402ResourceServer,
  syncFacilitatorOnStart?: boolean,
): void;
```

Registers Fastify hooks (`onRequest` and `onSend`) that:

1. Check if the incoming request matches a protected route
2. Validate payment headers if required
3. Return payment instructions (402 status) if payment is missing or invalid
4. Process the request if payment is valid
5. Handle settlement after successful response

#### Parameters

| Parameter | Required | Description |
|-----------|----------|-------------|
| `app` | Yes | The Fastify instance to register hooks on |
| `routes` | Yes | Route configurations for protected endpoints |
| `server` | Yes | Pre-configured `x402ResourceServer` instance |
| `syncFacilitatorOnStart` | No | Whether to sync with facilitator on startup (default: `true`) |

### Route Configuration

```typescript
const routes: RoutesConfig = {
  "GET /api/protected": {
    accepts: {
      scheme: "exact",
      price: "$0.10",
      network: "eip155:196",
      payTo: "0xYourAddress",
      maxTimeoutSeconds: 60,
    },
    description: "Premium API access",
  },
};

paymentMiddleware(app, routes, resourceServer);
```

### Multiple Protected Routes

```typescript
paymentMiddleware(
  app,
  {
    "GET /api/premium/*": {
      accepts: {
        scheme: "exact",
        price: "$1.00",
        network: "eip155:196",
        payTo: "0xYourAddress",
      },
      description: "Premium API access",
    },
    "GET /api/data": {
      accepts: {
        scheme: "exact",
        price: "$0.50",
        network: "eip155:196",
        payTo: "0xYourAddress",
        maxTimeoutSeconds: 120,
      },
      description: "Data endpoint access",
    },
  },
  resourceServer,
);
```
npm package: @okxweb3/x402-hono
Description: x402 Payment Protocol
Author: okfe
Latest version: 0.1.0

# @okxweb3/x402-hono

Hono middleware for the x402 Payment Protocol. Adds x402 payment requirements to Hono applications.

## Installation

```bash
npm install @okxweb3/x402-hono
```

## Quick Start

```typescript
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { paymentMiddleware, x402ResourceServer } from "@okxweb3/x402-hono";
import { ExactEvmScheme } from "@okxweb3/x402-evm/exact/server";
import { OKXFacilitatorClient } from "@okxweb3/x402-core/server";

const app = new Hono();

const facilitatorClient = new OKXFacilitatorClient();
const resourceServer = new x402ResourceServer(facilitatorClient)
  .register("eip155:196", new ExactEvmScheme());

app.use(
  paymentMiddleware(
    {
      "GET /protected-route": {
        accepts: {
          scheme: "exact",
          price: "$0.10",
          network: "eip155:196",
          payTo: "0xYourAddress",
        },
        description: "Access to premium content",
      },
    },
    resourceServer,
  ),
);

app.get("/protected-route", (c) => {
  return c.json({ message: "Premium content" });
});

serve({ fetch: app.fetch, port: 3000 });
```

## API Reference

### paymentMiddleware

```typescript
function paymentMiddleware(
  routes: RoutesConfig,
  server: x402ResourceServer,
  syncFacilitatorOnStart?: boolean,
): MiddlewareHandler;
```

Creates Hono middleware that:

1. Checks if the incoming request matches a protected route
2. Validates payment headers if required
3. Returns payment instructions (402 status) if payment is missing or invalid
4. Processes the request if payment is valid
5. Handles settlement after successful response

#### Parameters

| Parameter | Required | Description |
|-----------|----------|-------------|
| `routes` | Yes | Route configurations for protected endpoints |
| `server` | Yes | Pre-configured `x402ResourceServer` instance |
| `syncFacilitatorOnStart` | No | Whether to sync with facilitator on startup (default: `true`) |

### Route Configuration

```typescript
const routes: RoutesConfig = {
  "GET /api/protected": {
    accepts: {
      scheme: "exact",
      price: "$0.10",
      network: "eip155:196",
      payTo: "0xYourAddress",
      maxTimeoutSeconds: 60,
    },
    description: "Premium API access",
  },
};

app.use(paymentMiddleware(routes, resourceServer));
```

### Multiple Protected Routes

```typescript
app.use(
  paymentMiddleware(
    {
      "GET /api/premium/*": {
        accepts: {
          scheme: "exact",
          price: "$1.00",
          network: "eip155:196",
          payTo: "0xYourAddress",
        },
        description: "Premium API access",
      },
      "GET /api/data": {
        accepts: {
          scheme: "exact",
          price: "$0.50",
          network: "eip155:196",
          payTo: "0xYourAddress",
          maxTimeoutSeconds: 120,
        },
        description: "Data endpoint access",
      },
    },
    resourceServer,
  ),
);
```