Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Your first Solana subscriber in four steps

This page takes an empty project to one paying subscriber, in about ten minutes. It uses the React widget for the wallet part; without it, see subscriptions.create in the @mesub/node README. For the same steps with more explanation, read Solana recurring payments: add USDC subscriptions to your app.

Step 0: what you need

  1. Two wallets, in a wallet app such as Phantom or Solflare. One is yours: it signs the plan and receives the money. The other plays your customer.
  2. A little SOL on both, for network fees and rent: yours pays the plan's rent, the customer's the rent of their subscription.
  3. A little USDC on the customer's wallet, enough for one payment.
To try it without paying, use the fake Mesub in your tests first. For a first real charge, make a cheap plan, such as 1 USDC a day, subscribe with your second wallet, then cancel.
  1. Publish a plan
    In the dashboard, open Plans, then New plan: a name, a price, a token, a period, and the receiving wallet. To test, a price of 1 USDC charged every day is enough. An end, a day and a time to the minute in UTC, is optional.
    The organization wallet signs the plan's creation. The last button is always Sign and publish. When you are not signed in with that wallet, the link Send it to its holder hands the plan off, and it waits in To sign for that wallet: see organizations.
    Mesub derives the plan's slug, the dashboard's Slug, from its name: a plan named Pro gets pro. A slug is 2 to 50 lowercase letters, digits and single hyphens, with at least one letter. It is unique in the project and never reused, even after its plan ends. The slug is how your code names the plan everywhere below. You can read it in the plan's Set up tab, where the code on this page is already filled in with it.
  2. Give your server the API key
    In the dashboard, open Developers, then Keys, and press Create the key. The project's API key starts with SUB_ and is shown once: more on the key. Put it in your server's environment:
    MESUB_API_KEY=SUB_...
    Then install the SDK with your package manager:
    npm install @mesub/node
    pnpm add @mesub/node, yarn add @mesub/node and bun add @mesub/node work the same. It goes in dependencies: your server needs it in production.
  3. Mount the routes and gate a route
    Two things on your server. The routes are what the widget calls to subscribe and manage. The gate is the question you ask before serving anything paid. Both need to know who is asking, and that comes from your own login.
    import { Mesub } from '@mesub/node'; import { mesubRoutes } from '@mesub/node/express'; const mesub = new Mesub(); // reads MESUB_API_KEY // What the widget calls. Mount it after your own login. app.use( '/api/mesub', yourLogin, mesubRoutes({ customer: (req) => req.user ? { external_id: req.user.id } : null, }), ); // A paid route. app.get('/api/analytics', yourLogin, async (req, res) => { if (!(await mesub.hasAccess({ external_id: req.user.id }, 'pro'))) { res.status(402).json({ error: 'The Pro plan is needed.' }); return; } res.json(buildAnalytics(req.user)); });
    customer must come from a session you verified, never from what the browser sends. When it returns null, the routes answer 401. The Next.js and NestJS examples use the SDK's guards, which answer 401 and 402 themselves; Express has one too, requirePlan.
  4. Put the button on a page
    npm install @mesub/react
    It needs react and react-dom 18 or later. @mesub/react 0.1.x works with the routes of @mesub/node 0.1.x: keep the two at the same minor.
    Wrap your app once, pointing at where you mounted the routes:
    import { MesubProvider } from '@mesub/react'; import '@mesub/react/styles.css'; export function App({ children }) { return <MesubProvider endpoint="/api/mesub">{children}</MesubProvider>; }
    The wallet signs for mainnet, where your plans are.
    Then place the button, with the plan's slug:
    import { SubscribeButton } from '@mesub/react'; <SubscribeButton plan="pro">Subscribe to Pro</SubscribeButton>;

Try it

Sign in to your own site and click the button, with the customer's wallet. The window shows the plan, asks for a wallet, then for two approvals: the terms, then the first payment. Once it lands, /api/analytics answers for that customer.
You should see:
  • the subscription, active, under Subscriptions in the dashboard;
  • its first payment under Payments;
  • the price gone from the customer's wallet, and in your receiving wallet.
From here Mesub charges it every period without anything more from you.
Next: check access in detail, and webhooks to be told when a subscription renews, misses a payment or ends.