Nostr4J documentation

Nostr4J is a Java library for Nostr apps. It handles events, feeds and identities, and it also covers wallets, media storage and real-time peer-to-peer connections. It runs on desktop, mobile and in the browser, with the same API on every platform.

Platforms

The library runs on Windows, Linux, macOS, Android and iOS, and in the browser with TeaVM.

Target Platform adapter
Windows, Linux and macOS nge-platform-jvm
Android nge-platform-android
iOS nge-platform-ios
Browser, with JavaScript or WasmGC output nge-platform-teavm

See platform setup for more details.

Start building

Follow the quickstart example to sign a note, publish it and receive it through a subscription. You can also try the live demos before setting up a project.

From there, choose the part your app needs:

I want to… Start here
Let someone sign in with their Nostr identity Keys and signers
Publish a note or another kind of event Creating events and publishing
Load a feed and keep it up to date Filters, fetch and subscribe
Show or edit a profile Profile metadata and internet identifiers
Encrypt data for another user Message encryption
Deliver a sealed private message Gift-wrapped messages
Accept payments or upload media Wallets, zaps and Blossom
Exchange data between app users in real time Peer-to-peer real-time connections
Connect JVM code through input and output streams Simple P2P streams

For individual methods, consult the Javadoc. If you already know a NIP number, use the protocol index.

Keep data and manage connections

Use event stores and caches to retain events locally. The relay guides cover connection selection and background propagation. For rooms with particular connection needs, see RTC settings.

Asynchronous calls

Most network operations return an AsyncTask. Chain calls with .then() or .compose() in application code; the standalone examples often use .await() to keep the sequence easy to follow. Close subscriptions, pools and signers when you no longer need them, along with any keys your app owns.