Skip to content

Solid ​

Solid 1.8 and later 1.x are supported (tested with 1.9); Solid 2 is not supported yet. Read Integrate payments into your app first: it explains the service values, who creates invoices, and why onPaid is not proof of payment.

Install ​

sh
npm install @deadhop/client @deadhop/solid solid-js

Create the client once ​

ts
// src/deadhop.ts
import { createDeadhop } from '@deadhop/solid'; // same as '@deadhop/client'

export const deadhop = createDeadhop({
  serverPubkey: 'npub1…',
  relays: ['wss://relay.example.com'],
});

A pay button ​

tsx
import { PayButton } from '@deadhop/solid'
import '@deadhop/solid/styles.css';
import { deadhop } from './deadhop';

export const Tip = () => (
  <PayButton client={deadhop} amount={5000} memo="Thanks!" onPaid={(inv) => console.log('paid', inv.id)}>
    Tip 5,000 sats
  </PayButton>
);

The button text is children; without it the button reads Pay 5,000 sats. Needs public invoicing on the service.

An invoice form ​

tsx
import { InvoiceForm } from '@deadhop/solid';

export const Shop = () => <InvoiceForm client={deadhop} defaultAmount={21000} />;

An invoice your backend created ​

tsx
import { Invoice } from '@deadhop/solid';

export const Checkout = (props: { invoiceId: string }) => <Invoice client={deadhop} id={props.invoiceId} />;

See Backend for creating the invoice on your server.

Your own markup: useCheckout ​

tsx
import { Show } from 'solid-js';
import { useCheckout, InvoiceCard } from '@deadhop/solid';
import { LABELS } from '@deadhop/client';

export function Buy() {
  const [state, checkout] = useCheckout(deadhop, { onPaid: (inv) => console.log(inv.id) });
  return (
    <Show when={state().phase !== 'idle'} fallback={<button onClick={() => checkout.create({ amount_sat: 5000 })}>Buy</button>}>
      <InvoiceCard state={state()} labels={LABELS} />
    </Show>
  );
}

state is an accessor. The checkout stops polling when the owning component is disposed. To keep callbacks current, pass the component's props object (or getters) as the options.

SolidStart and server rendering ​

The package ships a compiled build and, under the solid export condition, JSX that SolidStart and other SSR setups compile themselves. Rendering on the server never opens a connection.

Language and styling ​

labels replaces any text, class adds a class to the outer element, and the stylesheet is optional; see Styling and page security. For faster proof of work on phones, see Faster proof of work.

deadhop 0.1.0 · Every page is also available as Markdown: replace .html with .md.