btc-rpc-client

Kotlin-based JSON-RPC client for bitcoind/btcd

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.jleskovar
ArtifactId

ArtifactId

btc-rpc-client
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

btc-rpc-client
Kotlin-based JSON-RPC client for bitcoind/btcd
Project URL

Project URL

https://github.com/jleskovar/btc-rpc-client.git
Source Code Management

Source Code Management

https://github.com/jleskovar/btc-rpc-client.git

Download btc-rpc-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jleskovar/btc-rpc-client/ -->
<dependency>
    <groupId>com.github.jleskovar</groupId>
    <artifactId>btc-rpc-client</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jleskovar/btc-rpc-client/
implementation 'com.github.jleskovar:btc-rpc-client:1.1.0'
// https://jarcasting.com/artifacts/com.github.jleskovar/btc-rpc-client/
implementation ("com.github.jleskovar:btc-rpc-client:1.1.0")
'com.github.jleskovar:btc-rpc-client:jar:1.1.0'
<dependency org="com.github.jleskovar" name="btc-rpc-client" rev="1.1.0">
  <artifact name="btc-rpc-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jleskovar', module='btc-rpc-client', version='1.1.0')
)
libraryDependencies += "com.github.jleskovar" % "btc-rpc-client" % "1.1.0"
[com.github.jleskovar/btc-rpc-client "1.1.0"]

Dependencies

compile (5)

Group / Artifact Type Version
com.github.briandilley.jsonrpc4j : jsonrpc4j jar 1.5.2
com.fasterxml.jackson.core : jackson-databind Optional jar 2.8.5
com.neovisionaries : nv-websocket-client Optional jar 2.3
org.jetbrains.kotlin : kotlin-stdlib jar 1.2.10
org.jetbrains.kotlin : kotlin-reflect Optional jar 1.2.10

Project Modules

There are no modules declared in this project.

btc-rpc-client

Kotlin-based JSON-RPC client for bitcoind/btcd. Requires jsonrpc4j (and optionally nv-websocket-client for WebSocket support)

Features

  • Supports all of the non-deprecated RPC methods exposed by the JSON-RPC interface in bitcoind and btcd
  • Data classes defined for all data types
  • Supports SSL (btcd only)
  • Experimental support for WebSocket interface (both synchronous and async - btcd only)

Usage

// Create a secure HTTP JSON-RPC Client to a local node
// NOTE: SSL supported only in btcd
val rpcClient = BitcoinRpcClientFactory.createClient(
        user = "james",
        password = "",
        host = "localhost",
        port = 8334,
        secure = true)
        
println(rpcClient.getBlockCount())
        
// OR: Create a WebSocket JSON-RPC client (btcd only)
val rpcClient = BitcoinRpcClientFactory.createWsClient(
        user = "james",
        password = "james",
        host = "localhost",
        port = 18334,
        secure = true

rpcClient.connect() // WS Clients must be explicitly connected/disconnected
println(rpcClient.getBlockCount())
rpcClient.disconnect()

// Asynchronous websocket (all methods return a CompletableFuture<T>)
val asyncWebSockets = BitcoinRpcClientFactory.createAsyncWsClient("james", "james", "localhost", 18334, true)

asyncWebSockets.connect()
val future: Future<Int> = asyncWebSockets.getBlockCount()
println(future.get())
asyncWebSockets.disconnect()

Maven

<dependency>
    <groupId>com.github.jleskovar</groupId>
    <artifactId>btc-rpc-client</artifactId>
    <version>1.0.0</version>
</dependency>

Notes

Should be compatible with bitcoind and btcd JSON-RPC interfaces, for methods implemented in btcd.

  • The default SSL mode is insecure, as it does not validate certificate paths. It is highly recommended a validating SSL context is created with appropriate truststores configured, by passing in the sslContext parameter to createClient

  • The websocket RPC interface in btcd offers superior performance compared to HTTP-based JSON-RPC, and is recommended for applications requiring heavy usage of the JSON-RPC interface (block iteration, transaction / address lookup, etc). On a 2016 macbook pro, running btcd in regtest mode:

     // Performance.kt
     Starting retrieval of first 1000 blocks using http client..
     http client took 30867 ms (32 requests/sec)
     Starting retrieval of first 1000 blocks using ws client..
     ws client took 250 ms (4000 requests/sec)
    
  • Repeated runs of the above test with 10000 blocks have yielded an average of ~8000 rps

Donation

Thanks! bitcoin:17bxks7R353xniuuTkbsEXwwqFn96vr2X7

Versions

Version
1.1.0
1.0.0