Gem Version Build Maintainability Test Coverage

Asynchronous Nostr client for Rubyists.

Table of contents

🔑 Key features

  • Asynchronous
  • Easy to use
  • Fully documented
  • Fully tested
  • Fully typed

📦 Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add nostr

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install nostr

⚡️ Quickstart

Here is a quick example of how to use the gem. For more detailed documentation, please check the documentation website.

# Require the gem
require 'nostr'

# Instantiate a client
client =

# a) Use an existing keypair
keypair =

# b) Or build a keypair from a private key
keygen =
keypair = keygen.get_key_pair_from_private_key('add-your-hex-private-key-here')

# c) Or create a new keypair
keygen =
keypair = keygen.generate_key_pair

# Create a user with the keypair
user = keypair)

# Create a signed event
text_note_event = user.create_event(
  kind: Nostr::EventKind::TEXT_NOTE,
  content: 'Your feedback is appreciated, now pay $8'

# Connect asynchronously to a relay
relay = 'wss://', name: 'Wine')

# Listen asynchronously for the connect event
client.on :connect do |relay|
  # Send the event to the Relay

  # Create a filter to receive the first 20 text notes
  # and encrypted direct messages from the relay that
  # were created in the previous hour
  filter =
    kinds: [
    since: - 3600, # 1 hour ago
    limit: 20,

  # Subscribe to events matching conditions of a filter
  subscription = client.subscribe(filter: filter)

  # Unsubscribe from events matching the filter above

# Listen for incoming messages and print them
client.on :message do |message|
  puts message

# Listen for error messages
client.on :error do |error_message|
  # Handle the error

# Listen for the close event
client.on :close do |code, reason|
  # You may attempt to reconnect to the relay here

# This line keeps the background client from exiting immediately.

📚 Documentation

I made a detailed documentation for this gem and it's usage. The code is also fully documented using YARD.

✅ Implemented NIPs

🔨 Development

After checking out the repo, run bin/setup to install dependencies.

To install this gem onto your local machine, run bundle exec rake install.

You can also run bin/console for an interactive prompt that will allow you to experiment.

To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to

The health and maintainability of the codebase is ensured through a set of Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:

rake build                    # Build nostr.gem into the pkg directory
rake build:checksum           # Generate SHA512 checksum if nostr.gem into the checksums directory
rake bundle:audit:check       # Checks the Gemfile.lock for insecure dependencies
rake bundle:audit:update      # Updates the bundler-audit vulnerability database
rake clean                    # Remove any temporary products
rake clobber                  # Remove any generated files
rake coverage                 # Run spec with coverage
rake install                  # Build and install nostr.gem into system gems
rake install:local            # Build and install nostr.gem into system gems without network access
rake qa                       # Test, lint and perform security and documentation audits
rake release[remote]          # Create a tag, build and push nostr.gem to
rake rubocop                  # Run RuboCop
rake rubocop:autocorrect      # Autocorrect RuboCop offenses (only when it's safe)
rake rubocop:autocorrect_all  # Autocorrect RuboCop offenses (safe and unsafe)
rake spec                     # Run RSpec code examples
rake verify_measurements      # Verify that yardstick coverage is at least 100%
rake yard                     # Generate YARD Documentation
rake yard:junk                # Check the junk in your YARD Documentation
rake yardstick_measure        # Measure docs in lib/**/*.rb with yardstick

Type checking

This gem leverages RBS, a language to describe the structure of Ruby programs. It is used to provide type checking and autocompletion in your editor. Run bundle exec typeprof FILENAME to generate an RBS definition for the given Ruby file. And validate all definitions using Steep with the command bundle exec steep check.

🐞 Issues & Bugs

If you find any issues or bugs, please report them here, I will be happy to have a look at them and fix them as soon as possible.

🤝 Contributing

Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

📜 License

The gem is available as open source under the terms of the MIT License.

👔 Code of Conduct

Everyone interacting in the Nostr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.