Skip to content

gstojsic/bitcoin-zmq

Repository files navigation

bitcoin-zmq

bitcoin-zmq is a java library that allows java applications to process bitcoin node zmq notifications.

requirements

The library requires a bitcoin node to connect to. For details on how to install a bitcoind node please refer to the Bitcoin documentation. Check this page to see how to configure zmq on your bitcoin node.

The project tests use testcontainers to run a bitcoin node in a docker container so docker needs to be installed to run tests.

usage

To use the library you have to add it as a dependency to your gradle project:

implementation("io.github.gstojsic.bitcoin:zmq:1.0")

or maven project:

<dependency>
    <groupId>io.github.gstojsic.bitcoin</groupId>
    <artifactId>zmq</artifactId>
    <version>1.0</version>
</dependency>

A simple example on how to use the library in your project is as follows:

try (var subscriber = new NotificationSubscriber("localhost", <<zmq port>>)) {
    subscriber.addSequenceListener((m) -> {
        //use m ... 
    });

    subscriber.run();
    //...
}

this assumes the bitcoin node is running on localhost on port zmq port.

related projects

If you need to connect to your bitcoin node via JSON RPC in your java application, checkout bitcoin-proxy