Solid
Gate features in a SolidJS extension popup with createUser from @extensionbill/sdk/solid.
createUser(bill) from @extensionbill/sdk/solid gives your component accessors for the current user, so <Show> blocks update by themselves after a purchase. Shared setup: Pick your stack.
Quick start
-
Create the project.
npm create vite@latest my-extension -- --template solid-ts cd my-extension npm install @extensionbill/sdk npm install -D @crxjs/vite-plugin -
Add the manifest. Replace
vite.config.ts; CRXJS builds every file the manifest references:// vite.config.ts import { defineConfig } from 'vite' import solid from 'vite-plugin-solid' import { crx } from '@crxjs/vite-plugin' export default defineConfig({ plugins: [ solid(), crx({ manifest: { manifest_version: 3, name: 'My Extension', version: '1.0.0', permissions: ['storage', 'alarms'], background: { service_worker: 'src/background.ts', type: 'module' }, action: { default_popup: 'index.html' }, }, }), ], }) -
Create the client and the background.
# .env.development VITE_EXTENSIONBILL_PUBLISHABLE_KEY=pk_test_…// src/bill.ts import { ExtensionBill } from '@extensionbill/sdk' export const bill = ExtensionBill({ publishableKey: import.meta.env.VITE_EXTENSIONBILL_PUBLISHABLE_KEY, })// src/background.ts import { bill } from './bill' bill.startBackground()Keep
startBackground()at the top level (why). -
Gate your popup. Replace
src/App.tsx(the template’ssrc/index.tsxalready renders it):// src/App.tsx import { Show } from 'solid-js' import { createUser } from '@extensionbill/sdk/solid' import { bill } from './bill' export default function App() { const account = createUser(bill) return ( <Show when={!account.loading()} fallback={<p>Loading…</p>}> <Show when={account.hasAccess('pro')} fallback={ <main> <button onClick={() => bill.openCheckout()}>Upgrade to Pro</button> <button onClick={() => bill.openRestore()}>Already paid? Restore</button> </main> } > <main> <p>Pro feature unlocked.</p> <button onClick={() => bill.openPortal()}>Manage subscription</button> </main> </Show> </Show> ) } -
Test a purchase. Run
npm run dev, load thedistfolder unpacked and buy Pro with a sandbox buyer (steps).
Advanced
Drop-in paywall
Swap your upgrade buttons for the ready-made Paywall UI. Mount it in onMount and pass the returned cleanup function to onCleanup:
// src/Paywall.tsx
import { onCleanup, onMount } from 'solid-js'
import { mountPaywall } from '@extensionbill/sdk/paywall'
import { bill } from './bill'
export function Paywall() {
let host!: HTMLDivElement
onMount(() => onCleanup(mountPaywall(host, bill, { title: 'Upgrade to Pro', theme: 'auto' })))
return <div ref={host} />
}
Use fallback={<Paywall />} on the hasAccess <Show>. Every option: Paywall UI.
What createUser returns
const { user, loading, error, hasAccess, refresh } = createUser(bill)
user(), loading() and error() are accessors (meaning of each field). hasAccess() reads user(), so it is reactive in JSX and createMemo().
Call createUser(bill) inside a component or root: it unsubscribes with onCleanup when its owner is disposed. Every component that calls it shares one load.
Keys per build
npm run build reads .env.production: put VITE_EXTENSIONBILL_PUBLISHABLE_KEY=pk_live_… there. Live keys work after going live.
Other build tools
- WXT:
npx wxt@latest init my-extensionwith the Solid template, then the WXT setup withmodules: ['@wxt-dev/module-solid'].App.tsxgoes inentrypoints/popup/.
Troubleshooting
Background, key and extension ID problems are covered in the shared troubleshooting.
Next steps
- Checking access in content scripts, the options page and the service worker
- Paywall UI labels and theming
- Free trials
- Going live checklist