Quick Start

Get Cron Protocol running in your project in minutes.

Install

bash
npm install @cron/sdk @cron/react

1. Create a plan (merchant)

Plans live on-chain. Create one from your backend or the dashboard. Each plan specifies a token, amount, billing interval, and optional metadata.

typescript
import { CronClient } from "@cron/sdk";
import { parseUnits } from "viem";

const cron = new CronClient({
  chain: "base",
  walletClient, // from wagmi or viem
});

const { planId } = await cron.plans.create({
  token: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
  amount: parseUnits("9.99", 6),
  interval: 30 * 24 * 60 * 60,      // 30 days in seconds
  gracePeriod: 3 * 24 * 60 * 60,    // 3-day grace period
  metadata: {
    name: "Pro Plan",
    description: "Unlimited access",
  },
});

console.log("Plan created:", planId);

2. Add the subscribe button (web app)

Drop <CronButton /> anywhere in your React app. It handles wallet connection, token approval, and subscription in one flow.

tsx
import { CronButton } from "@cron/react";

export function SubscribePage({ planId }: { planId: bigint }) {
  return (
    <CronButton
      planId={planId}
      chain="base"
      theme="dark"
      onSuccess={(sub) => {
        // Grant access — sub.subscriber is the wallet address
        grantAccess(sub.subscriber);
      }}
      onCancel={() => revokeAccess()}
    />
  );
}

3. Check subscription status

typescript
const status = await cron.subscriptions.getStatus({
  planId,
  subscriber: userAddress,
});

if (status === "Active") {
  // User has an active subscription
}

4. Run a keeper (charge automation)

Keepers scan the chain for due subscriptions and charge them, earning a 0.5% bounty per charge. Run the reference keeper with:

bash
cd packages/keeper
cp .env.example .env
# Fill in KEEPER_PRIVATE_KEY, CHAIN, RPC_URL, CRON_REGISTRY_ADDRESS
npm run start

5. Gate your API with micropayments (optional)

Use MPP to add pay-per-request pricing to any API endpoint. AI agents pay via sessions — no on-chain transaction per request.

bash
cd packages/x402-api
cp .env.example .env
# Fill in MPP_SECRET_KEY, PAYMENT_ADDRESS, CHAIN, CRON_REGISTRY_ADDRESS
npm run start

Test it:

bash
npx mppx http://localhost:4020/api/plans

[*] Dashboard shortcut

You can create and manage plans in the dashboard at app.cronprotocol.xyz without writing any code.

Next steps