Alex Gleason
Alex Gleason
Home About RSS Feed πŸ“‘ Admin
← Back to all articles

Sync your data between relays with nak

May 15, 2024 • 1 min read

nak is an awesome command-line tool written in Rust (jk, written in Go) for doing Nostr stuff. I use it on a daily basis to talk to relays and gather events.

Using nak, you can sync your data between one relay and another like this:

sh
nak req -a <pubkey> <relay-1> | nak event <relay-2>

For example:

sh
nak req -a 0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd wss://gleasonator.dev/relay | nak event wss://slime.church/relay

This downloads all data by the author (-a) from relay 1, and pipes it into relay 2.

Most relays only return about 100 events at a time, though. To sync everything you will need to implement some sort of pagination with since and until filters.

Most commonly I just need to sync my profile data to a new relay, which can be done with the -k (kind) flag. You can pass multiple -k flags, eg:

sh
nak req -k 0 -k 3 -k 10000 -k 10001 -k 10002 -k 10003 -a 0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd wss://gleasonator.dev/relay | nak event wss://slime.church/relay

This will migrate your profile, your follow list, your relay list, your mute list, pinned posts, and your bookmarks to the new relay.

If you find yourself doing this often, you can drop a little alias in your bashrc/zshrc:

sh
alias nsync="nak req -k 0 -k 3 -k 10000 -k 10001 -k 10002 -k 10003 -a 0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd wss://gleasonator.dev/relay | nak event"

Then you'll just nsync <relay> to copy data from your main relay to another relay!

Alex Gleason

Alex Gleason

I create software that empowers people online. I'm vegan btw.

alex@gleasonator.com
About Author
Alex Gleason
Alex Gleason βœ“ alex@gleasonator.com

I create software that empowers people online. I'm vegan btw.

Comments & Discussions (0)

Decentralized replies powered by Nostr (NIP-22 / NIP-10)
Loading Nostr comments...
🏷️ Topics
No items in this list.