Communicate with any participant, be it relays or clients, with elixir
This library is in the process of being built in the wild. It should at the moment be considered alpha quality. Function names and what they return will most probably be improved in the near future, so don't expect to write production code on top of it just yet. This is for education purposes only.
The current goal is to get feature complete with the most common NIPs, and will then be refined so it's as easy to use as can be.
def deps do
[
{:nostr, "~> 0.2.0"}
]
end
iex -S mix
NostrBasics.Keys.PrivateKey.create()
In the lib/examples, there is a NostrApp ready to be used. It connects to a relay and
retrieves your own notes and stuff. The easiest way to use it is to create a .iex.local.exs
file and paste that in
relays = [
"wss://relay.nostr.bg",
"wss://relay.nostr.pro"
]
private_key = NostrBasics.Keys.PrivateKey.create
NostrApp.start_link(relays, private_key)
and start iex
iex -S mix
%NostrBasics.Models.Profile{
about: "Instance of https://github.com/RooSoft/nostr being tested in the wild",
name: "roosoft_test_bot",
picture: "https://nostr.build/i/p/5158p.jpg"
}
|> NostrApp.update_profile()
NostrApp.profile
NostrBasics.Keys.PublicKey.from_private_key(private_key)
|> NostrApp.timeline()
You'll receive past and live events from all your followed contacts into the console, and are now able to send messages with that identity.
NostrApp.send_note("aren't you entertained?")
NostrApp.repost("note14n5txr742qzq4awx0mmd2x36tul9lrlrgfjvjpr6ev8h82z6yzqs5msdq7")
NostrApp.delete("note14n5txr742qzq4awx0mmd2x36tul9lrlrgfjvjpr6ev8h82z6yzqs5msdq7")
This is a bit rough around the edges still, but will be simplified soon
NostrApp.follow("npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z")
NostrApp.unfollow("npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z")
Could be yourself or anybody...
NostrApp.contacts("npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z")
NostrApp.encrypted_direct_messages
NostrApp.send_encrypted_direct_messages("npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z", "Howdy?")