Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {

Replace `[VERSION]` with the latest release number from the [releases page](https://github.com/tcheeric/nostr-java/releases).

For a quick API walkthrough, see [`docs/howto/use-nostr-java-api.md`](docs/howto/use-nostr-java-api.md).

See [`docs/CODEBASE_OVERVIEW.md`](docs/CODEBASE_OVERVIEW.md) for details about running tests and contributing.

## Examples
Expand Down
44 changes: 44 additions & 0 deletions docs/howto/use-nostr-java-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Using the nostr-java API

This guide shows how to set up the library and publish a basic [Nostr](https://github.com/nostr-protocol/nips) event.

## Minimal setup

Add the API module to your project:

```xml
<dependency>
<groupId>xyz.tcheeric</groupId>
<artifactId>nostr-java-api</artifactId>
<version>[VERSION]</version>
</dependency>
```

Replace `[VERSION]` with the latest release number.

## Create, sign, and publish an event

```java
import nostr.api.NIP01;
import nostr.id.Identity;

import java.util.Map;

public class QuickStart {
public static void main(String[] args) {
Identity identity = Identity.generateRandomIdentity();
Map<String, String> relays = Map.of("local", "wss://nostr.example");
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relay URL 'wss://nostr.example' appears to be a placeholder that won't work in practice. Consider using a real relay URL like 'wss://relay.damus.io' or add a comment explaining that users need to replace this with a working relay.

Suggested change
Map<String, String> relays = Map.of("local", "wss://nostr.example");
// Replace with your preferred relay if needed
Map<String, String> relays = Map.of("local", "wss://relay.damus.io");

Copilot uses AI. Check for mistakes.

new NIP01(identity)
.createTextNoteEvent("Hello nostr")
.sign()
.send(relays);
}
}
```

### Reference
- [`Identity.generateRandomIdentity`](../../nostr-java-id/src/main/java/nostr/id/Identity.java)
- [`NIP01.createTextNoteEvent`](../../nostr-java-api/src/main/java/nostr/api/NIP01.java)
- [`EventNostr.sign`](../../nostr-java-api/src/main/java/nostr/api/EventNostr.java)
- [`EventNostr.send`](../../nostr-java-api/src/main/java/nostr/api/EventNostr.java)