A small, self‑contained Nostr contact widget that you can use as a modal on any static site. Messages are encrypted on the client and sent via a configurable relay.
- There is a chat‑bubble button (
.nostr-chat-btn) that opens a modal on top of the page. - Inside the modal you write a message, which is encrypted via Nostr and sent as DMs (kind 4) to a fixed
npub. - For every message a fresh secret key is generated; you do not need to expose any
nsecin the frontend.
nostr-contact.js– controls the modal and sending over Nostr.nostr-contact-config.example.js– template for your own configuration.nostr-tools-entry.js– entry point for bundlingnostr-toolsinto a globalwindow.NostrToolsvariable.build-nostr-bundle.js– small build script for esbuild.src/nostr-contact.css– styles for the button, modal, textarea and send button.demo/index.html– simple example page where everything is wired together.
git clone <your-repo-url> quicknostr
cd quicknostr
npm install
npm run buildAfter npm run build, the bundled Nostr library is written to dist/nostr-tools-bundle.js.
-
Create a config file based on the example:
cp nostr-contact-config.example.js nostr-contact-config.js
The new file
nostr-contact-config.jslives next tonostr-contact.js. -
Edit
nostr-contact-config.jsand set your own values:window.NOSTR_CONTACT_CONFIG = { NOSTR_TARGET_NPUB: "npub1yourtargetaddress...", NOSTR_RELAY: "wss://nos.lol", };
- Include the CSS (adjust the path to your setup):
<link rel="stylesheet" href="/path/to/nostr-contact.css" />- Add a button to open the modal:
<button
type="button"
class="nostr-chat-btn"
id="nostrChatOpen"
aria-label="Send message"
>
<!-- Any icon you like, e.g. a chat bubble -->
</button>- Add the modal markup itself:
<div
class="nostr-contact-overlay"
id="nostrContactOverlay"
role="dialog"
aria-modal="true"
aria-label="Send message via Nostr"
aria-hidden="true"
>
<div class="nostr-contact-modal">
<button
type="button"
class="nostr-contact-close"
id="nostrContactClose"
aria-label="Close"
>
×
</button>
<textarea
id="nostrContactMessage"
class="nostr-contact-textarea"
placeholder="Message... please include phone number or email"
rows="4"
></textarea>
<button
type="button"
class="nostr-contact-send"
id="nostrContactSend"
>
Send
</button>
<p
class="nostr-contact-feedback"
id="nostrContactFeedback"
aria-live="polite"
></p>
<p class="nostr-contact-hint">
Messages are encrypted via Nostr and delivered through a relay.
</p>
</div>
</div>- Include the scripts in this order:
<script src="/path/to/nostr-contact-config.js"></script>
<script src="/path/to/nostr-tools-bundle.js"></script>
<script src="/path/to/nostr-contact.js"></script>After that, the button should open the modal, and the send button will send encrypted DMs to your configured npub.
The demo uses a license‑free monospace stack on the body:
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", "Courier New", monospace;You can reuse these fonts or replace them with your own. The widget works independently of the rest of your site design as long as the required classes (.nostr-chat-btn, .nostr-contact-overlay, .nostr-contact-modal, .nostr-contact-textarea, .nostr-contact-send) are present.
This project is licensed under the MIT License. You can use, modify, and redistribute the code in your own projects.