DEV Community

Cover image for Run a Nostr Relay on Your Phone with Termux and Fonstr
Melvin Carvalho
Melvin Carvalho

Posted on

Run a Nostr Relay on Your Phone with Termux and Fonstr

Explore a World of Possibilities: Run a Nostr Relay on Your Phone with Termux and Fonstr

Stay connected, be part of a decentralized network, and discover new opportunities


In this blog post, we'll show you how to set up a Nostr relay server on your Android phone, using Termux and 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.

  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:
pkg update && pkg upgrade
Enter fullscreen mode Exit fullscreen mode
  1. Next, install Node.js by entering:
pkg install nodejs
Enter fullscreen mode Exit fullscreen mode
  1. Finally, install Git with the following command:
pkg install git
Enter fullscreen mode Exit fullscreen mode

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:
git clone https://github.com/nostrapps/fonstr.git
Enter fullscreen mode Exit fullscreen mode
  1. Navigate to the project directory:
cd fonstr
Enter fullscreen mode Exit fullscreen mode
  1. Install the necessary dependencies:
npm install
Enter fullscreen mode Exit fullscreen mode

Running Your Nostr Relay: It's Showtime!

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

./index.js [port]
Enter fullscreen mode Exit fullscreen mode

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.
pkg install websocat
Enter fullscreen mode Exit fullscreen mode
  1. Open a terminal on your computer and enter the following command to connect to your Nostr relay:
websocat ws://[your-phone-ip]:[port]
Enter fullscreen mode Exit fullscreen mode

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 to create an event e.g.

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

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

To listen for new events try:

echo '["REQ", "fonstr", {}]' | websocat -n --ping-interval 20  ws://localhost:4444
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (1)

Collapse
 
lawrenceln profile image
Lawrence

How amazing was looking for something like this!!1
Thanks!!