Skip to content

NostrFollow Component

A button that allows website visitors to follow a Nostr profile with one click.

If NIP-07 window.nostr is not present in the page, https://github.com/fiatjaf/window.nostr.js will be included automatically when the button is clicked.

Usage

html
<script src="https://cdn.jsdelivr.net/npm/nostr-web-components/dist/nostr-follow.js"></script>
<nostr-follow pubkey="npub...">
  Follow me!
  <span slot="loading">Following...</span>
  <span slot="success">Followed!</span>
  <span slot="failure">Error: <span part="error-message"></span></span>
</nostr-follow>

Attributes

  • pubkey: The Nostr public key (npub or hex format) of the user to follow

Styling Parts

  • button: The follow button container
  • error-message: Error message text when follow fails,

Slots

  • Default: Main button text
  • loading: Shown while follow request is processing
  • success: Shown after successful follow
  • failure: Shown if follow request fails

Events

  • success: Fired when follow is successful. Event detail includes already: boolean indicating if user was already being followed.
  • failure: Fired when follow fails. Event detail includes error message.

External Templates

This component does not support external templates.