# Start your Nostr relay on Nym

To understand the will to have [Nostr](https://nostr.how/) relays working on the mixnet, please read the article [Nostr x Nym](https://blog.notrustverify.ch/nostr-x-nym-b1602320ecf0) which details our motivations.

The fact of having a Nostr relay that works through the mixnet will allow to protect the users as for example that their ISP can know that they are using Nostr, how often and to which relay, or to have the risk to see you asking for all the IP addresses that contacted your server. The system proposed here is functional with all current relays, it is still in development phase, so bugs are not excluded.

Here is the final architecture summarized

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680880485348/4f4a1ee9-722b-431a-b3b7-04b6c28247b6.jpeg align="center")

Several components are necessary to install to achieve this:

* A relay, a very complete list is available [here](https://github.com/aljazceru/awesome-nostr#relays). For this article, [nostr-rs-relay](https://sr.ht/~gheartsfield/nostr-rs-relay/) will be used because it is very simple, uses SQLite and runs easily on Docker
    
* nym-client, which will make the link between your relay and the mixnet
    
* nostr-nym, to "translate" the requests received from the mixnet and send them to the relay
    

### **Relay**

If you do not have Docker installed you can find the information here: [https://docs.docker.com/get-docker/](https://docs.docker.com/get-docker/). Docker is not essential for a relay to work but it greatly simplifies the explanations.

Now we have to start the relay :

```plaintext
mkdir data
docker run -it -p 7000:8080 \
  --mount src=$(pwd)/data,target=/usr/src/app/db,type=bind \
  scsibug/nostr-rs-relay
```

If all goes well, here is the output that should appear. The relay is now started.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680881296777/4dcd56d9-16f9-4bc2-b7fa-c2827641fd5c.avif align="center")

### **Nym-client**

The nym-client is the component that will allow to communicate with the mixnet.

The download is on Github: [https://github.com/nymtech/nym/releases](https://github.com/nymtech/nym/releases), you have to search for a release called "Nym Binaries v1.1.x". In this example, the version [Nym Binaries v1.1.14](https://github.com/nymtech/nym/releases/tag/nym-binaries-v1.1.14) is used.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680881366115/9e7002c1-0406-4eb7-a44a-ae778780eabb.avif align="center")

```plaintext
# Download the nym-client and give exec permission
wget https://github.com/nymtech/nym/releases/download/nym-binaries-v1.1.14/nym-client -O nym-client && chmod +x nym-client

# Init the nym-client
./nym-client init --id nostr-relay --latency-based-selection

# Start the nym-client
./nym-client run --id nostr-relay
```

If everything is correct the nym-client should now display its nym-client id. This is the element that will identify the relay and reach it in the mixnet.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680881510403/63ddfed0-40a5-4c0d-bf1e-a6563b086f05.jpeg align="center")

The window must remain open.

### **Nostr-nym**

It is this element that will make the link between the mixnet and the relay. It will establish a connection with the nym-client, listen to the messages sent by the clients, transmit the Nostr events and send back the answer or notify the clients.

For more flexibility, `pipenv` is used. To install [pip](https://pip.pypa.io/en/stable/installation/) is necessary: `pip install pipenv`

```plaintext
# clone the repo
git clone https://github.com/notrustverify/nostr-nym
cd nostr-nym

# start pipenv shell and install dependencies
pipenv shell
pipenv install
```

End result, the window must remain open.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680881709411/6a465d03-d77e-4a58-9d49-c410015ad041.jpeg align="center")

The relay is now accessible via the mixnet, in this example it is at the address (=nym-client id)

`5LhfbB9oGFEx4pTEUJ514LjCRuTr6zHq3kYmr45DeyAw.FfzyFK1GTAkRfpeKYMeQX3Ld1ascJUujXiHHozqunv6w@CfWcDJq8QBz6cVAPCYSaLbaJEhVTmHEmyYgQ6C5GdDW9` that it can be reached.

The following section explains how to test the relay, a simple nostr client has been developed.

### **Test**

Now that all the elements are in place, it is possible to test that creating notes and subscribing to new ones works.

In the previously cloned repository, there is a folder with a mixnet-compatible light Nostr client. Starting another nym-client is necessary.

```plaintext
# Init the nym-client
./nym-client init --id nostr-client --latency-based-selection --port 1978

# Start the nym-client
./nym-client run --id nostr-client
```

A public relay is available on the mixnet to easily test the operation :

`2gc9QidpXs4YGKmphinsDhWTHxdy2TZgWYWz2VenN5jL.dkwwJqS1zXa9BuPAFdniRN2HxFvAbTybAmrUHGAT5KV@2BuMSfMW3zpeAjKXyKLhmY4QW1DXurrtSPEJ6CjX3SEh`

```plaintext
# navigate to nostr client
cd nostr-nym/client

# start pipenv shell and install dependencies
pipenv shell
pipenv install
```

Publication of a new event.

```plaintext
python main.py --cmd text-note --message "Hello world (from the Nym mixnet)" --relay <nym-client of relay started before> --nym-client ws://127.0.0.1:1978
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680882155345/e9e02fb3-e002-4cb8-89dd-80a39f55281e.avif align="center")

Subscription to new events.

```plaintext
python main.py --cmd subscribe --relay <nym-client id of relay started before> --nym-client ws://127.0.0.1:1978
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680882232834/e90c9217-8fdc-4993-a678-b8ab8e87db94.jpeg align="center")

Event filtering.

```plaintext
python main.py --cmd filter --authors <npub to filter> --relay <nym-client id of relay started before> --nym-client ws://127.0.0.1:1978
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680882286165/4c621dcc-9067-41d7-82c7-52f953f4f280.jpeg align="center")

### Conclusion

The relay is now accessible via the mixnet. This is a first step towards more privacy and protection for relays.

A future article will present the benefits of setting up such an infrastructure for Nostr as well as the integration of the nym-client in an existing client such as [iris.to](http://iris.to), [snort.social](http://snort.social), [damus on iOS](https://damus.io/) or [Amethyst on Android](https://github.com/vitorpamplona/amethyst).

### **Resources:**

**Nostr-nym**

* [**https://github.com/notrustverify/nostr-nym/**](https://github.com/notrustverify/nostr-nym/)
    
* [**https://github.com/notrustverify/nostr-nym/tree/main/client**](https://github.com/notrustverify/nostr-nym/tree/main/client)
    

**Nym**

* [**https://nymtech.net/**](https://nymtech.net/)
    
* [**https://nymtech.net/docs/**](https://nymtech.net/docs/)
    
* [**https://nymtech.net/developers/**](https://nymtech.net/developers/)
    

---

%%[footer-english]
