DEV Community

Cover image for How to run a Nostr relay with nostream
chovy
chovy

Posted on

How to run a Nostr relay with nostream

If you haven't already heard Nostr is taking the Internet by storm after the recent Reddit API fiasco.

The Nostr protocol is a decentralized network protocol for a distributed social networking system. It is endorsed by notable figures such as Jack Dorsey, the co-founder of Twitter, and has early adopters like U.S. Senator Cynthia Lummis and Ethereum's creator Vitalik Buterin​1​.

On a technical level, the Nostr network consists of two main components: clients and relays. The clients serve as interfaces that users utilize to read and write data to the relays, much like a social media app. The relays function like databases, storing data sent by clients and making it available for clients to read​2​.

Every user in the Nostr network is identified by a public key, and every event object (e.g., a message, update to a following list, etc.) is signed. Clients validate these signatures to ensure they're correct. The data that can be seen on Nostr is dependent on the relays to which a user decides to connect​2​.

Events are the only object type on the network. Each event object has a kind, which denotes the type of event it is (what sort of action a user might take or messages that might be received)​2​. There are many different kinds of events, from metadata (kind 0) to short text notes (kind 1) to encrypted direct messages (kind 4) and so on​2​.

Standardized tags are used for creating links, adding media, and mentioning other users or events. These include 'e' for event id, 'p' for public key, 'a' for coordinates to an event, 'r' for a reference (URL, etc.), 't' for hashtag, and more​2​.

A Nostr Implementation Possibility (NIP) documents what must, should, and may be implemented by Nostr-compatible relay and client software. Since Nostr is decentralized and not owned by a centralized service, the direction of the protocol is up to the collective, meaning that changes can be suggested and feedback can be offered on ideas suggested by others​2​.

Here is how you set up Nostream:

First clone the repo at https://github.com/Cameri/nostream/

You'll need docker-compose installs, I won't bother writing out instructions for that.

Generate a secret with: openssl rand -hex 128 Copy the output and paste it into an .env file:

SECRET=xyz

Then type: npm run docker:compose:start

There's a bug in ./scripts/start where docker compose is two words, you'll need to change that to docker-compose (hyphenated). Then the rest of the install will work.

It will automatically listen on port 8008 so you can proxy that using nginx.

You'll need docker-compose installs, I won't bother writing out instructions for that.

Generate a secret with: openssl rand -hex 128 Copy the output and paste it into an .env file:

SECRET=xyz

Then type: npm run docker:compose:start

There's a bug in ./scripts/start where docker compose is two words, you'll need to change that to docker-compose (hyphenated). Then the rest of the install will work.

It will automatically listen on port 8008 so you can proxy that using nginx.

Verifying the install

To verify the install you can install the websocat package: yay -S websocat and run: websocat wss://relay.your-domain.com
T

Top comments (0)