Skip to main content

Get started in three steps

Transform your API into a revenue stream with Solana micropayments in minutes.

Step 1: Install CheapPay

Install CheapPay using your preferred package manager:
npm install @cheapay/x402 @cheapay/x402-express
For Next.js projects, use @cheapay/x402-next instead of @cheapay/x402-express
CheapPay provides framework-specific packages for seamless integration:
  • @cheapay/x402 - Core types and utilities
  • @cheapay/x402-express - Express.js middleware
  • @cheapay/x402-next - Next.js middleware
Start with the core package and your framework-specific middleware.

Step 2: Set up payment middleware

Add payment protection to your Express API in seconds:
import express from 'express';
import { solanaPaymentMiddleware } from '@cheapay/x402-express';
import { TokenMint } from '@cheapay/x402';

const app = express();

// Protect your premium endpoint with $0.01 USDC payment
app.use('/api/premium', solanaPaymentMiddleware({
  payTo: 'YourSolanaWalletAddressHere',
  routes: {
    '/*': {
      price: '$0.01',
      network: 'solana-devnet', // Use devnet for testing
      mint: TokenMint.USDC.devnet,
      description: 'Premium API access'
    }
  }
}));

// Your protected endpoint
app.get('/api/premium/data', (req, res) => {
  res.json({
    message: 'Premium content unlocked!',
    data: 'This cost $0.01 USDC to access'
  });
});

app.listen(3000, () => {
  console.log('💰 Payment-enabled API running on port 3000');
});
For Next.js projects, create a middleware.ts file:
import { solanaPaymentMiddleware } from '@cheapay/x402-next';
import { TokenMint } from '@cheapay/x402';

export const middleware = solanaPaymentMiddleware(
  'YourSolanaWalletAddressHere',
  {
    '/api/premium/*': {
      price: '$0.01',
      network: 'solana-devnet',
      mint: TokenMint.USDC.devnet,
      description: 'Premium API access'
    }
  }
);

export const config = {
  matcher: ['/api/premium/:path*']
};
Your Next.js API routes are now payment-protected automatically!

Step 3: Test your integration

  1. Start your server and navigate to your protected endpoint
  2. See the payment prompt - CheapPay automatically shows a beautiful paywall
  3. Connect your Solana wallet (Phantom, Solflare, or Backpack)
  4. Complete the payment - Users pay $0.01 USDC to access your API
  5. Receive instant payment - USDC appears in your wallet immediately
Testing tip: Use Solana devnet for free testing with fake USDC tokens. Switch to solana-mainnet and TokenMint.USDC.mainnet for production.

Next steps

Now that you have payments working, explore these advanced features:

Environment setup

For production use, set up these environment variables:
# Your Solana wallet address (receives payments)
CHEAPAY_WALLET_ADDRESS=YourSolanaWalletAddressHere

# Network configuration
SOLANA_NETWORK=solana-mainnet  # or solana-devnet for testing

# Optional: Custom facilitator URL
FACILITATOR_URL=https://api.cheappay.com/v1/x402
Security reminder: Never expose private keys in your code. CheapPay only needs your public wallet address to receive payments.

Need help?

I