Why Nostr? What is Njump?
2024-05-15 23:06:49

Sync your data between relays with nak

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:

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

For example:

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:

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:

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!

Author Public Key
npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p