Docs
Sidejar is two HTML tags and a few helper functions. A payer pays a small, one-time amount of USDC from their own wallet straight to yours. Your page decides what a payment unlocks.
Quick start
Add the script once per page, then a button:
<script type="module" src="https://sidejar.com/sidejar.js"></script>
<sidejar-pay to="0xYourWalletAddress" price="0.20" item="post-42"></sidejar-pay>
That’s a working tip jar. To unlock something when it’s paid, add a <sidejar-content> block:
<sidejar-pay id="tip" to="0xYourWalletAddress" price="0.20" item="post-42"></sidejar-pay>
<sidejar-content for="tip">
<template><p>Thanks for your support! Here's the bonus chapter…</p></template>
</sidejar-content>
The Generator builds both tags for you, including encrypted content.
Testing: add
network="base-sepolia"to use Base Sepolia, a test network with free, worthless USDC (from faucet.circle.com, choosing Base Sepolia). Without it, payments are real money on Base.
<sidejar-pay>
The payment button.
Attributes
| Attribute | Required | Meaning |
|---|---|---|
to |
yes | Your wallet address (receives the money). |
price |
yes | Amount in USDC, as a decimal: "0.20" is 20¢. From 0.01 (one cent) up to 5 USDC. The full amount reaches the recipient: no fees are taken out. |
item |
yes | A unique ID for what’s being paid for. Each wallet can pay for an item only once. Add {date}, {week}, {month} or {year} to allow one payment per period (see below). |
network |
no | base (real money, the default) or base-sepolia (test network). Test jars log a console warning. |
label |
no | The button’s text, with {price} filled in: label="Tip the author {price}". Default: “Pay {price}”. |
Your own label
Two ways, for the ready-to-pay button:
<!-- Text with the price filled in -->
<sidejar-pay to="0x…" price="0.20" item="post-42" label="Tip the author {price}"></sidejar-pay>
<!-- Or anything you put inside the tag (shown as-is, so write the price yourself) -->
<sidejar-pay to="0x…" price="0.20" item="post-42">☕ Buy me a coffee (20¢)</sidejar-pay>
Content inside the tag wins over label, and it’s also what readers see if the script hasn’t loaded. Other states (“Confirm in your wallet…”, “Thanks! Paid…”) keep Sidejar’s wording.
Always close the tag: write
<sidejar-pay …></sidejar-pay>, never<sidejar-pay … />. HTML has no self-closing custom tags, so everything after a/>ends up inside the button. Sidejar notices this, ignores it as a label, and warns in the console. (JSX, Astro, Vue and Svelte handle/>for you.)
Paying again: dynamic item IDs
Each wallet can pay for an item once. To let people pay again (a tip jar, a daily donation), make the ID change over time with a placeholder:
<sidejar-pay to="0x…" price="1.00" item="support-{date}"></sidejar-pay>
| Placeholder | Becomes | One payment per wallet per… |
|---|---|---|
{date} |
2026-11-28 |
day |
{week} |
2026-W48 |
week (ISO, Monday to Sunday) |
{month} |
2026-11 |
month |
{year} |
2026 |
year |
Dates use the payer’s local time zone, so “per day” rolls over at their own midnight. Events report the filled-in ID. For any other rule, set the attribute from your own script: jar.setAttribute("item", "anything-" + yourValue).
What payers see
| State | Button |
|---|---|
| No wallet installed | “To pay, you need a crypto wallet with a little USDC.” with a “How to pay →” link to a short guide |
| Ready | “Pay 20¢”, or “Pay 20¢ from 0x1a2…” when a wallet is already connected |
| Waiting | “Confirm in your wallet…” |
| Sending | “Sending payment…” |
| Paid | “Thanks! Paid 20¢”, plus a “View transaction” link once confirmed |
| Error | A short message and “Try again” |
| Misconfigured | “This payment button is misconfigured.” (check the console and sidejar:error) |
Payers need USDC in their wallet but no ETH: they sign once, and the payment service pays the network fee.
Events
All events are CustomEvents fired on the element. They bubble, so you can listen on document too.
| Event | When | detail |
|---|---|---|
sidejar:ready |
The button is set up | { network, walletDetected, connected, payer? } |
sidejar:paid |
Payment accepted, or already paid (on page load) | { item, payer, to, amount, nonce, restored, txHash? } |
sidejar:settled |
The transaction is confirmed on-chain | { item, payer, to, amount, nonce, txHash } |
sidejar:cancelled |
The payer declined in their wallet | { item, stage } ("connect", "switch" or "sign") |
sidejar:error |
Something failed, or a warning | { item, code, message, warning? } (see Error codes) |
document.querySelector("sidejar-pay").addEventListener("sidejar:paid", (e) => {
console.log(e.detail.restored ? "Paid earlier" : "Just paid", e.detail.amount);
});
amount is a decimal string like "0.20". restored: true means this wallet paid on an earlier visit: Sidejar remembers payments by checking the blockchain, so a returning payer is recognized without any account.
The element also has a read-only paidDetail property: the last sidejar:paid detail for the current payer, or null.
Styling
The button lives in shadow DOM, so your site’s CSS can’t break it. Style it with CSS custom properties:
sidejar-pay {
--sidejar-accent: #c2410c; /* button color */
--sidejar-radius: 6px;
}
| Property | Default use |
|---|---|
--sidejar-accent, --sidejar-accent-fg |
Button background (Sidejar teal, #0f766e, by default) and text |
--sidejar-fg, --sidejar-muted |
Text colors |
--sidejar-success, --sidejar-error, --sidejar-link |
Paid message, error message, links |
--sidejar-font, --sidejar-font-size |
Typography |
--sidejar-radius, --sidejar-padding |
Button shape |
The button shows Sidejar’s jar icon before its label; its coin drops in while waiting and stacks up when paid. Hide it with sidejar-pay::part(icon) { display: none; }.
For more control, use the shadow parts jar, button, icon, message and link (sidejar-pay::part(button) { … }), or the element’s data-state attribute (loading, nowallet, ready, waiting, sending, paid, error, invalid).
<sidejar-content>
Holds what a payment unlocks, and reveals it when its <sidejar-pay> is paid, including when a returning payer loads the page.
<sidejar-content for="tip" onlocked="Sidejar.blur" onpaid="Sidejar.decrypt">
<template>sj1.…encrypted content…</template>
</sidejar-content>
Attributes
| Attribute | Meaning |
|---|---|
for |
The id of the <sidejar-pay> to follow. Optional when the page has exactly one. |
onlocked |
A function whose return value is shown before payment (a preview). |
onpaid |
A function that turns the content into what’s shown after payment. Without it, the template is shown as-is. |
onready, onsettled, oncancelled, onfailed |
Functions called on the matching <sidejar-pay> event (onfailed = sidejar:error). Return values are ignored. |
data-key |
A key for Sidejar.decrypt (see Encryption). |
for works like <label for="…">: it names the jar by its id. In React JSX, write it as htmlFor, React’s name for the for attribute.
Handlers
Handler attributes name a function: one of the built-in Sidejar methods (Sidejar.blur) or your own. It’s called as:
fn(content, detail, el)
// content: the template's HTML (or JSON text) as a string
// detail: the event's detail (null for onlocked)
// el: the <sidejar-content> element
- Return a string of HTML or a DOM node (or a Promise of one) to show it. Return
undefinedif your function displayed things itself. - If
onpaidthrows or rejects, the content stays locked and the element firessidejar:errorwithcontent_handler_failed. - Define your own handlers with a function declaration (or
window.myFn = …). Top-levelconstandletaren’t visible to attributes. - In frameworks, set handlers as properties instead:
el.onpaid = (content) => …. Properties win over attributes.
<script>
function shout(content) {
return content.toUpperCase();
}
</script>
<sidejar-content for="tip" onpaid="shout"><template><p>hello</p></template></sidejar-content>
Previews
onlocked decides what readers see before paying: a blurred version, the first few words, grey lines, or nothing. Previews are hidden from screen readers, which hear “Locked content” instead. When a blurred preview unlocks, the real content animates into focus.
JSON content
Put JSON in a <script type="application/json"> instead of a <template>, which would mangle & and <. It’s never executed, and your onpaid gets the raw text:
<sidejar-content for="tip" onpaid="showAnswers">
<script type="application/json">{ "answers": ["B", "D", "A"] }</script>
</sidejar-content>
<script>
function showAnswers(content) {
const data = Sidejar.json(content);
return `<p>Answers: ${data.answers.join(", ")}</p>`;
}
</script>
Chained jars
Put another <sidejar-pay> (with its own <sidejar-content>) inside revealed content. It appears only after the first payment, then works on its own: chapter 1, then chapter 2. Give each jar its own item, and set for="…" whenever a page has more than one jar.
Good to know
- Scripts inside revealed content don’t run (browsers never run scripts in inserted HTML). Tags like a nested
<sidejar-pay>do work. - Once unlocked, content stays unlocked, even if the payer switches wallets. Sidejar never hides content; your page decides.
- It’s a block element by default (override with any CSS).
- For styling, it always has the class
sidejar-content, plus one state, as a class and asdata-state:sidejar-locked,sidejar-unlocking(while decrypting),sidejar-unlockedorsidejar-failed. Your own classes are left alone. See the paywall in the demos.
Sidejar methods
Built-in functions on the global Sidejar object. Use them by name in attributes (onlocked="Sidejar.blur") or call them from your code. Each takes the content as a string and returns a string, so they combine.
| Method | Use | Returns |
|---|---|---|
Sidejar.blur(content) |
preview | Scrambled text, blurred. The real words are never in the preview. |
Sidejar.teaser(content, { words }) |
preview | The first words words (default 40), fading out. |
Sidejar.placeholder(content) |
preview | Grey skeleton lines about as long as the content. |
Sidejar.scramble(content) |
preview | Same layout, every letter and digit randomized; links and images stripped. |
Sidejar.decrypt(content, key?) |
unlock | Decrypts content made by Sidejar.encrypt. As a handler, uses data-key or the default key. Async. |
Sidejar.decryptWith(key) |
unlock | A decrypt function bound to your key. |
Sidejar.decodeBase64(content) |
unlock | Decodes base64 (UTF-8). |
Sidejar.json(content) |
unlock | Parses JSON, with a clear error if it’s invalid. |
Sidejar.reveal(content) |
unlock | The content as-is (the default). |
Sidejar.encrypt(content, key?) |
tooling | Encrypts content: returns "sj1.…". Async. |
Sidejar.encodeBase64(content) |
tooling | Encodes as base64 (UTF-8). |
Combining them in your own function:
<script>
function teaserAndBlur(content) {
return Sidejar.teaser(content, { words: 30 }) + Sidejar.blur(content);
}
</script>
<sidejar-content for="tip" onlocked="teaserAndBlur">…</sidejar-content>
Encryption
Light encryption keeps content out of View Source, copy-paste and search engines. It is not strong protection: the key is in your page, so a determined person can decrypt it. It’s meant to stop casual cheating.
Encrypt in any of these places (it’s the same code everywhere):
- The Generator, in your browser. Nothing is sent anywhere. Best for static sites.
- Your server or build step, with
sidejar-crypto.js(1.5 KB, no browser code; Node 18+, Workers, Deno, Bun). Download it fromhttps://sidejar.com/sidejar-crypto.jsinto your project, then:
import { encrypt } from "./sidejar-crypto.js";
const html = `<template>${await encrypt("<p>Members only</p>", "my-key")}</template>`;
Decrypt in onpaid, one of three ways:
<!-- 1. No key: content encrypted with the default key -->
<sidejar-content for="tip" onpaid="Sidejar.decrypt">…</sidejar-content>
<!-- 2. A key on the element -->
<sidejar-content for="tip" onpaid="Sidejar.decrypt" data-key="my-key">…</sidejar-content>
<!-- 3. Your own function that passes the key -->
<script>
function myDecrypt(content) {
return Sidejar.decrypt(content, "my-key");
}
</script>
<sidejar-content for="tip" onpaid="myDecrypt">…</sidejar-content>
A wrong key keeps the content locked and fires content_handler_failed. Previews of encrypted content show gibberish of about the right length.
Teasers and encryption: a teaser can only show real words if they’re in the page, so Sidejar.teaser on encrypted content shows gibberish. For a readable opening, put the opening paragraph in the page as normal text and encrypt only the rest, previewed with Sidejar.blur or Sidejar.placeholder. See the demos.
Error codes
sidejar:error always has a stable code to match on. message is English text for developers.
| Code | Fired on | When |
|---|---|---|
invalid_to, invalid_price, invalid_item, invalid_network |
<sidejar-pay> |
An attribute is missing or wrong. The button shows “misconfigured”. |
network_unavailable |
<sidejar-pay> |
Payments on that network aren’t available. |
wallet_error |
<sidejar-pay> |
The wallet failed for a reason other than the payer declining. |
rpc_unreachable |
<sidejar-pay> |
The blockchain couldn’t be reached before signing. |
relay_unreachable, relay_error |
<sidejar-pay> |
The payment service couldn’t be reached, or answered oddly. |
relay_rejected |
<sidejar-pay> |
The payment service refused the payment (it didn’t look like a Sidejar payment). |
relay_rate_limited |
<sidejar-pay> |
Too many attempts from one connection; try again in a minute. |
e.g. invalid_exact_evm_insufficient_balance |
<sidejar-pay> |
The payment was declined: the code is the reason (here, not enough USDC). Falls back to verify_failed or settle_failed. |
settlement_failed |
<sidejar-pay> |
The transaction failed on-chain after sidejar:paid. The payer can try again. |
settlement_unconfirmed |
<sidejar-pay> |
A warning (warning: true): sent, but not confirmed in time. It probably went through. |
content_pay_not_found, content_pay_ambiguous |
<sidejar-content> |
It can’t tell which <sidejar-pay> to follow. Set for="…". |
content_handler_failed |
<sidejar-content> |
A handler is missing or threw (for example, a wrong decryption key). |
Skip warnings when showing failures:
document.addEventListener("sidejar:error", (e) => {
if (!e.detail.warning) console.warn(e.detail.code, e.detail.message);
});
How a payment works
- The payer taps the button and connects their wallet (and switches to Base, if needed).
- Their wallet shows one signature request: a TransferWithAuthorization for the exact amount to your address. In wallets, the amount appears in USDC’s smallest units:
200000means 0.20 USDC. - Sidejar sends that signed authorization to its payment service, which checks it and submits it to the blockchain, paying the network fee.
- USDC moves directly from the payer’s wallet to yours. Sidejar never holds the money and can’t change the amount or the recipient: both are part of what the payer signed.
- Each payment uses an ID derived from the item, your address and the payer, so the USDC contract itself refuses to charge twice for the same item.
Limits and good to know
- Honor-level. Unlocked content lives in your page (encrypted or not). Sidejar stops casual readers, not determined ones, and a payer can always share what they’ve unlocked.
- Files behind links (like a PDF) are public to anyone with the URL. Use unguessable file names, don’t link the file elsewhere, and tell search engines not to index it.
- Payments: USDC only, on Base; one payment per wallet per item; at most 5 USDC.
- Content management systems: you need to be able to add a
<script>tag and custom HTML. Self-hosted WordPress works for administrators (Custom HTML block); WordPress.com needs a plan that allows custom code; Substack and Medium don’t allow it. - Privacy: Sidejar has no accounts and stores nothing about payers. To see which sites use it, the payment service records only the site and recipient of each successful payment.