Skip to content

Instantly share code, notes, and snippets.

@vishalxl
Last active April 12, 2023 04:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalxl/68b3feca2dafad543e6e52a0e0b3038f to your computer and use it in GitHub Desktop.
Save vishalxl/68b3feca2dafad543e6e52a0e0b3038f to your computer and use it in GitHub Desktop.
Nostr commands for Bash Terminal on Linux ( also available on Windows 10 as Ubuntu WSL)

Read Events On Command Line

Print all events:

This would print the latest 100 events:

echo '["REQ", "a", {"limit": 100} ]' | websocat wss://nostr-pub.wellorder.net

Pretty print all events

echo "[\"REQ\",\"latest\",{\"limit\": 100}]" |websocat wss://nostr-pub.wellorder.net |while read -r line; do jq -j ' "\n-------------\ntime  : ", ( .[2].created_at | todate),"\nAuthor: ", (.[2].pubkey | .[0:6]),"\nPost  : ", .[2].content, "\n" ' ; done

Pretty print all events in last one day:

echo "[\"REQ\",\"latest_details\",{\"since\":$(date -d '-1 day' +%s),\"limit\": 100}]" |  websocat wss://relay.damus.io |while read -r line; do jq -j ' "\n-------------\ntime : ", ( .[2].created_at | todate),"\nAuthor: ", (.[2].pubkey | .[0:6]),"\nPost : ", .[2].content, "\n" ' ; done

To fetch a single event

for server in  "wss://relay.nostr.info"     "wss://nostr-relay.wlvs.space"    "wss://nostr-pub.wellorder.net"  "wss://relay.damus.io"   "wss://nostr.delo.software"  "wss://nostr-pub.semisol.dev" "wss://nostr-relay-dev.wlvs.space"  ; do     req="[\"REQ\",\"l\",{\"ids\":[\"97c3680b533cf54ed67f3fcd291e934dcfbf72e4dadb8824a6f8f99c70061f5b\"]}]"  ; echo  $req  $server ; echo "$req" | websocat -B 300000 $server ; done

Test Servers

To test how servers are working, get events for last 1 hour

for server in  "wss://relay.nostr.info"     "wss://nostr-relay.wlvs.space"    "wss://nostr-pub.wellorder.net"  "wss://relay.damus.io"   "wss://nostr.delo.software"  "wss://nostr-pub.semisol.dev" "wss://nostr-relay-dev.wlvs.space"  ; do    sinceSeconds=`date -d '-1 hour' +%s` ; req="[\"REQ\",\"l\",{\"since\":$sinceSeconds}]"  ; echo  $req  $server ; echo "$req" | websocat -B 300000 $server | wc

To get events in multiple calls

unt=0; for server in  "wss://relay.nostr.info"     "wss://nostr-relay.wlvs.space"    "wss://nostr-pub.wellorder.net"  "wss://relay.damus.io"   "wss://nostr.delo.software"  "wss://nostr-pub.semisol.dev" "wss://nostr-relay-dev.wlvs.space"  ;  do  echo $server ;    for since in 6 12 18 24 ; do  echo -$since -$unt ;   sinceSeconds=`date -d "-$since hours" +%s`  ; untilSeconds=`date -d "-$unt hours" +%s` ; req="[\"REQ\",\"l\",{\"since\":$sinceSeconds,\"until\":$untilSeconds}]"  ; echo  $req  $server ; echo "$req" | websocat -B 300000 $server | wc  ; unt=$since;  done ;   done

Using Nostril

 nostril --envelope --sec 0000000000000000000000000000000000000000000000000000000000000001 --created-at 1668869760   --content 'this' 
@ok300
Copy link

ok300 commented Aug 25, 2022

Very helpful, but please add a limit

echo '["REQ", "a", {"limit": 5} ]' | websocat wss://nostr-pub.wellorder.net

Whoever needs to adjust it, will adjust it. But without it people will just copy-paste and overload the relays.

@vishalxl
Copy link
Author

Edited..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment