An open API service indexing awesome lists of open source software.

https://github.com/grunch/nostr-publisher-template


https://github.com/grunch/nostr-publisher-template

Last synced: 28 days ago
JSON representation

Awesome Lists containing this project

README

          

# nostr-publisher-template

Minimal Rust template for publishing notes to Nostr with `nostr-sdk 0.44.1`.

## What it does

- loads `NOSTR_NSEC` or `--secret-key`
- loads relays from `--relay` and/or `NOSTR_RELAYS`
- uses a built-in base relay set if none is provided
- expands the built-in relay set with `--all-relays`
- normalizes relays by removing trailing `/` and deduplicates the list
- publishes a `kind 1` text note
- prints `event_id`, successful relays, and failed relays
- attempts to verify the event by `id` on the configured relays

## Relay priority

1. repeated `--relay` flags in the CLI
2. `NOSTR_RELAYS` as a comma-separated list
3. built-in relays by default
4. if you pass `--all-relays`, the expanded relay list is added too

## Quick start

```bash
cp .env.example .env
# fill in NOSTR_NSEC and, if you want, NOSTR_RELAYS
cargo run -- --content "Hello Nostr"
```

Or with flags:

```bash
cargo run -- \
--secret-key "nsec1..." \
--relay wss://relay.damus.io \
--relay wss://nos.lol/ \
--content "Hello Nostr"
```

To use the expanded relay list:

```bash
cargo run -- --all-relays --content "Hello Nostr"
```

## Notes

- `npub` is not enough to publish.
- If there are no explicit relays, the binary uses the built-in base set.
- Relay verification may take a little while depending on indexing.
- URLs are normalized to remove trailing slashes, so `wss://nos.lol/` and `wss://nos.lol` are treated the same.
- For Notion posts with media:
- the script downloads the attachment and uploads it to nostr.build using `NOSTR_BUILD_NPUB` and `NOSTR_BUILD_PASSWD`
- if the attachment is already hosted on nostr.build, the script reuses that public URL as-is
- the public URL returned by nostr.build is the one used in the Nostr post