Skip to content

nitinsurana/Litecoin-Bitcoin-RPC-Java-Connector

Repository files navigation

Introduction

This project is a java library that is intended to provide a wrapper around JSON-RPC provided by Bitcoin/Litecoin.

It has been tested on Litecoin. I wrote it for one of my projects.

The main dependencies of this project are

*   **Htmlunit**	
*   **Google Gson**

Since this was intended for use in a proprietary project, I've tried to write as much javadoc as possible as to what the method does.

JSON-RPC calls for Litecoin & Bitcoin are same as you can see below, so this work shall work with both. If it doesn't please let me know by filing an issue.

Litecoin RPC API Calls

Bitcoin RPC API Calls

This project assumes that the one who uses it has a preliminary knowledge about Bitcoin/Litecoin and how to start the RPC server.

Running Litecoin

Running Bitcoin

Sample Usage

public static void main(String[] args) throws Exception {
    final String rpcUser = "rpcuser";
    final String rpcPassword = "password";
    final String rpcHost = "localhost";
    final String rpcPort = "9332";
    CryptoCurrencyRPC cryptoCurrencyRPC = new CryptoCurrencyRPC(rpcUser, rpcPassword, rpcHost, rpcPort);

    cryptoCurrencyRPC.setAccount("account","LCYEnDaddressENBYCEYD235NSD");
    
    //Similarly, all the API methods can be called.
}

Blockchain Events

(part of the code was taken from https://github.com/johannbarbie/BitcoindClient4J)

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

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

You can register observers to capture events of wallets, and alerts:

    WalletListener walletListener = new WalletListener(cryptoCurrencyRPC, 4002);
    walletListener.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            System.out.println("Amount of transaction: " + ((Transaction)arg).getAmount());
        }
    });

Make sure to close sockets later:

  walletListener.stop();

License

Copyright (c) 2014-2015 Nitin Surana | Licensed under the MIT license.

Written with StackEdit.

About

A wrapper around the JSON-RPC provided by the bitcoin/litecoin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages