If you sell an Electron app, licensing needs two things: a way to activate a key once, and a check on every launch that still works offline. This post shows both with @keygrant/electron.
(Disclosure: we build KeyGrant. We made it because a new app usually has no customers yet, and licensing shouldn't cost you anything before you've sold a copy. It's free until your app takes off, with no hidden fees and no revenue share.)
What you need
- A KeyGrant account (free up to 250 active licenses) and a product in the dashboard
- A license key: issue one under Licenses > Issue a license, or create a test license
- Node.js 20 or later. The SDK runs in Electron's main process, not in a renderer.
1. Install the SDK
npm install @keygrant/electron 2. Get your public key
Your app checks each license with your product's public key. Fetch it once and ship it with the app. The request needs no API key:
curl https://api.keygrant.dev/v1/products/my-product/pubkey -
my-productis your product's API ID, the last part of its page's URL in the dashboard. - Keep the
keysarray from the response. You pass it to the SDK unchanged. - The dashboard's Signing key tab has a Copy key set button that copies the same thing.
3. Activate a key
Create one License for the process, and activate the key your customer enters:
import { License } from "@keygrant/electron"; const license = new License({ product: "my-product", apiBaseUrl: "https://api.keygrant.dev", publicJwks: PUBLIC_KEYS, // the keys from step 2 major: 1, // this build's major version }); const result = await license.activate(userEnteredKey); if (!result.ok) showActivationError(result.error); activate checks the key with KeyGrant, takes one of the key's device seats for this machine, and stores a signed license (a JWT) on the device. When it fails, result.error says why, such as invalid-key or limit.
4. Check the license on every launch
async function checkLicense() { const status = await license.status(); if (status.state === "licensed" || status.state === "trial") return; // run if (status.state === "unknown") { // The license file could not be read: keep running and check again shortly. setTimeout(checkLicense, 5_000); return; } // "expired" or "invalid": status.reason says why. "unlicensed": no key is stored yet. showActivationWindow(status); } checkLicense(); status() checks the stored license on the device and usually needs no network. When the license is close to its end, it renews it first, waiting at most 5 seconds for KeyGrant. If KeyGrant can't be reached, your app keeps working until the license runs out.
Selling it
Connect your Stripe account in the dashboard and pick the Stripe price for each license model. Each paid checkout then creates a key, with no code on your side. To have KeyGrant email the key to the buyer, choose KeyGrant sends them on the product's License delivery tab.
Your app's Buy button just opens your Stripe Payment Link:
import { shell } from "electron"; await shell.openExternal("https://buy.stripe.com/your-link"); // Once they have the key from the email: const result = await license.activate(enteredKey); Selling through Paddle instead? Its checkouts create keys the same way: https://keygrant.dev/docs/getting-started/paddle
Next
- Full quick start: https://keygrant.dev/docs/getting-started
- Electron SDK reference: https://keygrant.dev/docs/sdks/electron
You can ship licensing on day one and pay nothing until you pass 250 active licenses. Questions welcome in the comments.
