Frameworks and CSP
Sidejar is one script tag and two HTML elements. There's nothing to install: it works anywhere you can add a script and some HTML. This page covers the details for frameworks, and for sites with a Content Security Policy.
Add the script
Once per page, ideally in the <head> of your layout or template:
<script type="module" src="https://cdn.sidejar.com/v1/sidejar.js"></script>
Then write <sidejar-pay> and <sidejar-content> anywhere, as in the docs. The elements are a browser standard (custom elements), so they work with any framework, and with server rendering: the server sends the tags as plain HTML and they come to life when the script loads.
Events: in any framework, the dependable way to react to a payment is addEventListener("sidejar:paid", …) on the element (or on document, since the events bubble).
React
Write the tags in JSX. Tested with React 18 and 19:
for: writefor="tip". Don't usehtmlFor: on these elements React passes it through as an attribute literally namedhtmlfor, which Sidejar doesn't read.- Classes: React 19 turns
classNameintoclass. React 18 doesn't (it becomesclassname), so in React 18 writeclass. - Text attributes like
to,price,item,effectandonpaid="Sidejar.decrypt"pass through unchanged. - Your own functions: set them as properties with a ref, not as attributes.
import { useEffect, useRef } from "react";
export function Article() {
const jar = useRef(null);
useEffect(() => {
const el = jar.current;
const onPaid = (e) => console.log("Paid", e.detail.amount);
el.addEventListener("sidejar:paid", onPaid);
return () => el.removeEventListener("sidejar:paid", onPaid);
}, []);
return (
<>
<sidejar-content for="tip" effect="fade">
<p>The opening paragraph…</p>
</sidejar-content>
<sidejar-pay ref={jar} id="tip" to="0xYourWallet" price="0.20" item="post-42"></sidejar-pay>
<sidejar-content for="tip" onpaid="Sidejar.decrypt">
<template dangerouslySetInnerHTML={{ __html: "sj1.…" }} />
</sidejar-content>
</>
);
}
The <template> uses dangerouslySetInnerHTML because React won't put children inside a template's content. The string is your encrypted text, so nothing unsafe is injected.
Next.js (App Router): put the script tag in the <head> of app/layout.tsx. The tags render on the server as plain HTML; no "use client" is needed unless you attach listeners as above.
TypeScript
TypeScript doesn't know these tags, so JSX shows type errors. Add a declaration file to your project, for example sidejar.d.ts:
import "react";
type SidejarProps = React.HTMLAttributes<HTMLElement> & {
ref?: React.Ref<HTMLElement>;
class?: string;
[attribute: string]: unknown;
};
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"sidejar-pay": SidejarProps & { to: string; price: string; item: string; label?: string };
"sidejar-content": SidejarProps & { for?: string; effect?: string; onpaid?: string };
}
}
}
Vue
Tell Vue these are custom elements, so it doesn't try to resolve them as components. With Vite:
// vite.config.js
import vue from "@vitejs/plugin-vue";
export default {
plugins: [vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith("sidejar-") } } })],
};
Then use the tags in templates as written in the docs, for included. For events, use a template ref and addEventListener("sidejar:paid", …) in onMounted.
Svelte and others
Svelte, Solid, Lit, Angular (with CUSTOM_ELEMENTS_SCHEMA), and plain server-rendered sites (Rails, Django, PHP, WordPress) need nothing special: write the tags and add the script. Listen for sidejar:paid with addEventListener.
Astro
Add the script with is:inline, so Astro leaves it as-is:
<script is:inline type="module" src="https://cdn.sidejar.com/v1/sidejar.js"></script>
The tags go straight into .astro files. sidejar.com itself is built with Astro.
Avoiding a flash
The script loads after the page is shown, so for a moment exposed content can appear before its effect applies (for example, the real words before a scramble). To hide it until Sidejar is ready, add this to your CSS:
sidejar-content[effect]:not(:defined) { visibility: hidden; }
:not(:defined) matches the element only until the script has loaded.
Content Security Policy
If your site sends a Content Security Policy, Sidejar needs:
| Directive | Value | Why |
|---|---|---|
script-src |
https://cdn.sidejar.com |
The script itself |
connect-src |
https://relay.sidejar.com |
Submitting payments |
connect-src |
https://mainnet.base.org |
Checking past payments and confirmations on Base |
For example:
Content-Security-Policy: script-src 'self' https://cdn.sidejar.com; connect-src 'self' https://relay.sidejar.com https://mainnet.base.org
Good to know:
- No
'unsafe-inline'styles needed. Sidejar adds its styles with constructed stylesheets, which a strictstyle-srcallows. (Very old browsers without them fall back to a<style>element.) The optional stand-in helpersSidejar.blur,Sidejar.teaserandSidejar.placeholderdo use inlinestyleattributes; skip them, or allowstyle-src-attr 'unsafe-inline'. - Wallets aren't affected: the page talks to wallet extensions through the browser, not over the network.
- Links such as "View transaction" (basescan.org) are ordinary links, not requests.
- Trusted Types (
require-trusted-types-for 'script') isn't supported yet: decrypted content is inserted as HTML.