nostr-gem/docs/relays/connecting-to-a-relay.md
2023-11-13 17:48:17 +07:00

836 B

Connecting to a Relay

You must connect your nostr Client to a relay in order to send and receive Events. Instantiate a Nostr::Client and a Nostr::Relay giving it the url of your relay. The name attribute is just descriptive. Calling Client#connect attempts to establish a WebSocket connection between the Client and the Relay.

client = Nostr::Client.new
relay = Nostr::Relay.new(url: 'wss://relay.damus.io', name: 'Damus')

# Listen for the connect event
client.on :connect do
  # When this block executes, you're connected to the relay
end

# Connect to a relay asynchronously
client.connect(relay)