Giter Site home page Giter Site logo

bitcoindclient4j's Introduction

Bitcoind Json Rpc Client for Java

Build Status

This is a Java library to call the Json Rpc API of the reference implementation Bitcoind. The goal is to support all methods listed in the ./bitcoind help-command. The implementation started from version 0.8.3 of Bitcoind and will not support previous versions. For further details about the implemented API visit the bitcoin.org wiki. Currently tested version is 0.9.0.

Build

Having OpenJDK 7 and Maven 3 installed, execute:

  mvn clean install

Usage

Maven will need to know where to search for this artifact. Add this to your pom.xml:

  <repository>
    <id>github</id>
    <name>GitHub BitcoindClient4j Repository</name>
    <url>https://raw.github.com/johannbarbie/BitcoindClient4j/mvn-repo</url>
  </repository>

Then add the dependency itself:

  <dependency>
    <groupId>com.37coins</groupId>
    <artifactId>BitcoindClient4J</artifactId>
    <version>0.2.0-SNAPSHOT</version>
  </dependency>

Having dependencies resolved, you can code away. First initialize the Factory with network parameters:

  BitcoindClientFactory clientFactory = 
      new BitcoindClientFactory(
          new URL("http://localhost:8332/"), 
          "user", 
          "password");

Then get a client instance:

  BitcoindInterface client = clientFactory.getClient();

Now you can make calls to your node:

  Info info = client.getinfo();

If you had the API start your bitcoind, you might be interested in stopping it again:

  client.stop();

Blockchain Events

The library also captures notifications from Bitcoind using the startup configuration. Launch your deamon with those parameters:

  ./bitcoind  -blocknotify="echo '%s' | nc 127.0.0.1 4001" 
              -walletnotify="echo '%s' | nc 127.0.0.1 4002" 
              -alertnotify="echo '%s' | nc 127.0.0.1 4003" 
              -daemon

Or, if you have your bitcoind locally, have the API start up the daemon. Call the factory with a path instead of network parameters:

  BitcoindClientFactory clientFactory = 
      new BitcoindClientFactory(
          "/home/user/.bitcoin/",
          Arrays.asList("./bitcoind"));

You can register observers to capture events about blocks, addresses in you wallet, and alerts:

  new BlockListener(client).addObserver(new Observer() {
    @Override
    public void update(Observable o, Object arg) {
      Block block = (Block)arg;
    }
  });

Make sure to close sockets later:

  blockListener.stop();

Donations

Bitcoin donations can be sent to:

  152jsQJyQwxRywuHVVGLFEHkZqJ4QzuFS3

Thanks!

License

GPL3, see LICENSE.txt

bitcoindclient4j's People

Contributors

johannbarbie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.