Aptos x402 LogoAptos x402
x402 Payment Protocol for Aptos

Aptos-native
x402 payment protocol

Monetize your APIs with blockchain micropayments.

Install via npm

npm install aptos-x402
200+weekly downloads

Zero Payment Logic

Just configure middleware. Your API routes stay clean—no payment code needed.

Fast Finality

Built on Aptos blockchain. Verification in <50ms, settlement in 1-3 seconds.

x402 Compliant

Follows Coinbase x402 specification for machine-to-machine micropayments.

Simple to implement

Three steps to monetize your APIs

1

Configure middleware

Set recipient address
Configure protected routes
Set price per request
// middleware.ts
import { paymentMiddleware }
  from 'aptos-x402';

export const middleware =
  paymentMiddleware(
    process.env
      .PAYMENT_RECIPIENT_ADDRESS!,
    {
      '/api/premium/weather': {
        price: '1000000',
        network: 'testnet',
      }
    },
    { url: process.env
        .FACILITATOR_URL! }
  );
2

Write your API route

No payment logic needed
Payment verified automatically
Focus on your business logic
// route.ts
import { NextResponse }
  from 'next/server';

export async function GET() {
  // Payment already verified!

  return NextResponse.json({
    temperature: 72,
    condition: 'Sunny',
    premium: true
  });
}
3

Client pays automatically

Detects 402 response
Signs transaction
Retries with payment
// client.ts
import { x402axios }
  from 'aptos-x402';

const result = await x402axios.get(
  'https://api.example.com/premium/weather',
  {
    privateKey: '0x...'
  }
);

// Done! Payment handled
console.log(result.data);

aptos-x402

Built for the Aptos ecosystem