BitcoindConnector4J is a Java library to call the JSON-RPC API of the Bitcoind server.
+------------------------------------------+
| JVM |
+----------+ +---------------------+ +----------+ |
| | JSON-RPC | | | | |
Bitcoin P2P net <--> | Bitcoind | <------> | BitcoindConnector4J | <--> | Java App | |
| | | | | | |
+----------+ +---------------------+ +----------+ |
| |
+------------------------------------------+
Import library in pom.xml:
<dependency>
<groupId>com.sulacosoft</groupId>
<artifactId>BitcoindConnector4J</artifactId>
<version>0.2.0</version>
</dependency>
Example how to connect and call methods:
import java.util.Map;
import com.sulacosoft.bitcoindconnector4j.BitcoindApi;
import com.sulacosoft.bitcoindconnector4j.BitcoindApiFactory;
import com.sulacosoft.bitcoindconnector4j.core.BitcoindConnector4JException;
import com.sulacosoft.bitcoindconnector4j.response.Info;
public class ExampleMain {
public static void main(String[] args) throws BitcoindConnector4JException {
// bitcoind server connection parameters
String address = "127.0.0.1";
int port = 8333;
String protocol = "http";
String user = "bitcoind_user";
String password = "bitcoind_password";
// create api
BitcoindApi api = BitcoindApiFactory.createConnection(address, port, protocol, user, password);
// call getinfo
Info info = api.getinfo();
System.out.println("Protocol version: " + info.getProtocolversion());
System.out.println("Total balance : " + info.getBalance());
// call listaccounts
Map<String, Double> accounts = api.listaccounts();
accounts.forEach((k, v) -> System.out.println(String.format("account %s balance : %s", k, v)));
}
}
For compilation we need JDK 8 and Gradle 2.x. The following commands build jar:
$ gradle build
Provide code examples and explanations of how to get the project.
Complete bitcoin API command list are available on page link
Currently connector implemented methods:
- getaccount
- getaccountaddress
- getaddressesbyaccount
- getreceivedbyaddress
- getconnectioncount
- getnewaddress
- getbalance
- getbestblockhash
- getblock
- getdifficulty
- getgenerate
- gethashespersec
- getinfo
- gettransaction
- listaccounts
- listreceivedbyaccount
- listtransactions
- listsinceblock
- move
- sendfrom
- validateaddress
Sebastian Dziak ([email protected]) Nicola Atzei ([email protected])
BitcoindConnector4J is distributed under the Apache License 2.0.