← Back to Home

Example 04: Subscription Service with USDC Billing

This example shows how Lazorkit smart wallets can power subscription-style payments using USDC, without requiring users to manage gas or private keys.

What You’ll Learn

  • Authorizing payments using passkeys
  • Using smart wallets for recurring billing logic
  • Sending USDC without requiring SOL for gas
  • Building subscription-style payment flows

How It Works

1. Wallet Authorization

The user connects once using passkey authentication.

2. USDC Payment Instruction

A USDC transfer instruction represents the subscription charge.

3. Gasless Billing

Lazorkit paymaster sponsors the transaction fee.

Code Example

Minimal subscription-style USDC billing using Lazorkit smart wallets.

import { useWallet } from "@lazorkit/wallet";
import { PublicKey } from "@solana/web3.js";
import { createTransferInstruction } from "@solana/spl-token";

const MERCHANT = new PublicKey("MERCHANT_WALLET_ADDRESS");

export function SubscribeButton() {
  const { smartWalletPubkey, signAndSendTransaction } = useWallet();

  async function subscribe() {
    if (!smartWalletPubkey) return;

    // Build a USDC payment instruction (represents one billing cycle)
    const ix = createTransferInstruction(
      smartWalletPubkey, // payer (simplified for example)
      MERCHANT,          // subscription owner
      smartWalletPubkey,
      5_000_000          // 5 USDC (6 decimals)
    );

    // Lazorkit signs & sends using passkeys (no wallet extensions)
    await signAndSendTransaction({
      instructions: [ix],
      transactionOptions: { feeToken: "USDC" },
    });
  }

  return <button onClick={subscribe}>Subscribe – 5 USDC / month</button>;
}