Run a Nostr Relay on Your Phone with Termux and Fonstr
Tags: nostr, fonstr, relay, phone
Published: 2023-05-07 06:54:21

<div align="center">
  <h1>Explore a World of Possibilities: Run a Nostr Relay on Your Phone with Termux and Fonstr</h1>
</div>

<div align="center">
  <i>Stay connected, be part of a decentralized network, and discover new opportunities</i>
</div>

---

In this blog post, we'll show you how to set up a [Nostr](https://nostr.com) relay server on your Android phone, using [Termux](https://termux.dev/en/) and [Fonstr](https://github.com/nostrapps/fonstr), so you can join this exciting world of decentralized communication even if you're not a tech expert.

## Getting Started: Installing Termux

First things first, let's get Termux installed on your Android phone. Termux is a powerful terminal emulator that allows you to run a Linux environment on your Android device. 

To install Termux, follow these simple steps:

1. Download and install the F-Droid app store on your phone. F-Droid is an alternative app store for Android that focuses on free and open-source software. You can download F-Droid from [their website](https://f-droid.org/).

2. Open F-Droid, search for "Termux," and install the app.

## Preparing Your Phone with Termux

Now that you have Termux installed on your phone, let's set up the environment:

1. Open Termux and enter the following command to update the package list and upgrade the installed packages:

```bash
pkg update && pkg upgrade
```

2. Next, install Node.js by entering:

```bash
pkg install nodejs
```

3. Finally, install Git with the following command:

```bash
pkg install git
```

Great! You've just set up your phone to run a Nostr relay.

## Installing Fonstr: Your Nostr Relay Server

With your environment ready, it's time to install Fonstr:

1. In Termux, clone the Fonstr repository with the following command:

```bash
git clone https://github.com/nostrapps/fonstr.git
```

2. Navigate to the project directory:

```bash
cd fonstr
```

3. Install the necessary dependencies:

```bash
npm install
```

## Running Your Nostr Relay: It's Showtime!

With everything set up, you can now run your Nostr relay server:

```bash
./index.js [port]
```

Replace `[port]` with the desired port number. If no port is provided, the server will run on port 4444 by default.

Hooray! Your Nostr relay server is up and running on your Android phone, and you're now part of the Nostr decentralized network.

## Testing Your Relay with Websocat

To make sure everything is working correctly, you can test your relay using Websocat. Websocat is a command-line tool that allows you to interact with WebSocket servers.

1. Install Websocat on your computer by following the instructions on [their GitHub page](https://github.com/vi/websocat).

```bash
pkg install websocat
```

2. Open a terminal on your computer and enter the following command to connect to your Nostr relay:

```bash
websocat ws://[your-phone-ip]:[port]
```

Replace `[your-phone-ip]` with your phone's IP address and `[port]` with the port number you used when starting the relay.

You should now be able to communicate with your Nostr relay!

## Test Events

To test sending an event you can use [NAK](https://nak.nostr.com) to create an event e.g.

```json
{
  "content": "hello world",
  "created_at": 1683206612,
  "id": "9d87daf61771777d73ea901efd3771f142fbc887283d75771dbeda030d725c7e",
  "kind": 1,
  "pubkey": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
  "sig": "54be52723617100b776730cc8c1871698b222ddfae4bbbd47627705593e09731f147708b3808b14b71fdcac0bcd6e3fef11442b48f0d5cbca7e58d2e03ae4d53",
  "tags": []
}
```

Send ["EVENT", <your event] via websocat 

To listen for new events try:

```bash
echo '["REQ", "fonstr", {}]' | websocat -n --ping-interval 20  ws://localhost:4444
```
## Conclusion

You've just opened a world of possibilities by setting up a Nostr relay server on your Android phone. This achievement not only allows you to stay connected to a decentralized network but also empowers you to explore new opportunities in the world of communication and collaboration. By following these simple steps, even non-technical users can join and contribute to the Nostr network.

As you become more familiar with Nostr and its potential, you might want to explore other Nostr applications and tools to expand your knowledge and capabilities. With the power of decentralized communication at your fingertips, the sky's the limit!

Don't hesitate to share your Nostr relay experience with friends and fellow enthusiasts. By spreading the word about the Nostr protocol and its benefits, we can build a more robust, decentralized, and open network for everyone to enjoy.

Happy exploring!