diff --git a/README.md b/README.md index afc1de39f..a137079b9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/howto/use-nostr-java-api.md b/docs/howto/use-nostr-java-api.md new file mode 100644 index 000000000..d08be83aa --- /dev/null +++ b/docs/howto/use-nostr-java-api.md @@ -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 + + xyz.tcheeric + nostr-java-api + [VERSION] + +``` + +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 relays = Map.of("local", "wss://nostr.example"); + + 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)