How to Import and Export Your Nostr Notes

Learn how to import your Nostr notes from public relays and export them into your own relay using the nak CLI tool. This step-by-step guide covers installation, fetching notes, filtering by event types, and uploading to a self-hosted relay—ensuring your content is safe and under your control.

How to Import and Export Your Nostr Notes

This guide will help you import your notes from various Nostr relays and export them into your own relay. This is particularly useful when you want to ensure your content is backed up or when you're setting up your own relay.

Prerequisite

Your own Nostr relay (if you don't have one, check out Part 1: How to Run Your Own Nostr Relay)

Installing nak

nak is a command-line tool that helps you interact with Nostr relays. Here's how to install it:

For Windows Users

  1. Visit the nak releases page
  2. Download the latest nak-windows-amd64.exe
  3. Rename it to nak.exe
  4. Move it to a directory in your PATH or use it from its current location

For macOS Users

  1. Visit the nak releases page
  2. Download the latest nak-darwin-amd64
  3. Open Terminal and run:
    chmod +x nak-darwin-amd64
    sudo mv nak-darwin-amd64 /usr/local/bin/nak
    

For Linux Users

  1. Visit the nak releases page
  2. Download the latest nak-linux-amd64
  3. Open Terminal and run:
    chmod +x nak-linux-amd64
    sudo mv nak-linux-amd64 /usr/local/bin/nak
    

Getting Your Public Key in Hex Format

Before downloading your notes, you need to convert your npub (public key) to its hex format. If you have your npub, run:

nak decode npub1YOUR_NPUB_HERE

This will output your public key in hex format, which you'll need for the next steps.

Downloading Your Notes

To download your notes, you'll need your public key in hex format and a list of reliable relays. Here are some popular relays you can use:

  • wss://eden.nostr.land/
  • wss://nos.lol/
  • wss://nostr.bitcoiner.social/
  • wss://nostr.mom/
  • wss://relay.primal.net/
  • wss://relay.damus.io/
  • wss://relay.nostr.band/
  • wss://relay.snort.social/

Note: You should check your Nostr client's settings to find additional relays where your notes are published. Add these to the list above.

Important Event Kinds

Here are some important event kinds you might want to filter for:

  • 0: User Metadata (profile information)
  • 1: Short Text Notes
  • 3: Follow List
  • 4: Encrypted Direct Messages

Get the full list from: https://nips.nostr.com/#event-kinds

Downloading with Event Kind Filters

To download your notes with specific event kinds, use the -k flag followed by the kind number, use multiple if you need to. For example, to download your profile, short notes, follow list, and direct messages:

nak req -a YOUR_HEX_PUBKEY -k 0 -k 1 -k 3 -k 4 wss://eden.nostr.land/ wss://nos.lol/ wss://nostr.bitcoiner.social/ wss://nostr.mom/ wss://relay.primal.net/ wss://relay.damus.io/ wss://relay.nostr.band/ wss://relay.snort.social/ > events_filtered.json

Or to download all your content, just don't provide any k flag:

nak req -a YOUR_HEX_PUBKEY wss://eden.nostr.land/ wss://nos.lol/ wss://nostr.bitcoiner.social/ wss://nostr.mom/ wss://relay.primal.net/ wss://relay.damus.io/ wss://relay.nostr.band/ wss://relay.snort.social/ > events.json

This will create a file containing all your notes in JSON Lines format.

Uploading Your Notes to Your Relay

Once you have your events.json or events_filtered.json file, you can upload it to your own relay. Replace YOUR_RELAY with your relay's WebSocket URL (e.g., wss://my-relay.nostrize.me).

nak event YOUR_RELAY < events.json

Important Notes:

  1. Make sure your relay is running and accessible
  2. The upload process might take some time depending on how many notes you have
  3. You can verify the upload by querying your relay for your notes

Verifying the Upload

To verify that your notes were successfully uploaded to your relay, run:

nak req -a YOUR_HEX_PUBKEY YOUR_RELAY

This should return the same notes that were in your events.json file.

Troubleshooting

If you encounter any issues:

  1. Make sure your relay is running and accessible
  2. Check that you're using the correct public key
  3. Verify that the relays in your download list are working
  4. Ensure you have proper permissions to write to your relay

Next Steps

  • Remember to regularly backup your notes to ensure you don't lose any content.
  • If you want to keep your friends' notes as well, add npubs that you want to import into your relay's settings (for Citrine it is "Accept events signed by" list), and run the commands for their pubkeys.